Issues with Boost Library for x86_32 Architecture on Ubuntu 22.04 – How to Manage Conflicts with x86

I'm working on a C++ project that uses the Boost program_options library on Ubuntu 22.04 system with an Intel Core i7 processor. I've successfully compiled and run the project for x86_64 architecture using the following command:
g++ program.cpp -m64 -static -lboost_program_options -o compiled/program.out
g++ program.cpp -m64 -static -lboost_program_options -o compiled/program.out
So when I try to compile for x86_32 architecture using -m32, I encounter the following error:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../libboost_program_options.a when searching for -lboost_program_options
/usr/bin/ld: skipping incompatible /usr/lib/libboost_program_options.a when searching for -lboost_program_options
/usr/bin/ld: cannot find -lboost_program_options
collect2: error: ld returned 1 exit status
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../libboost_program_options.a when searching for -lboost_program_options
/usr/bin/ld: skipping incompatible /usr/lib/libboost_program_options.a when searching for -lboost_program_options
/usr/bin/ld: cannot find -lboost_program_options
collect2: error: ld returned 1 exit status
I've attempted to install the 32-bit Boost library using
sudo apt-get install libboost_program_options-dev:i386
sudo apt-get install libboost_program_options-dev:i386
but it conflicts with the 64-bit version. How can I effectively manage Boost library installations for both x86 and x86_64 architectures on the same system? Are there any alternative approaches or workarounds to avoid conflicts and ensure compatibility?
Solution:
Was receiving a linker error indicating that it cannot find the 32-bit Boost library, and I noticed that some of my project's dependencies might also require specific 32-bit libraries , but I was able to manage these with pkg-config . Thanks
Jump to solution
5 Replies
wafa_ath
wafa_ath3mo ago
U can start with 1. Install multilib support: sudo apt-get install gcc-multilib g++-multilib' 2. Install both 32-bit and 64-bit Boost libraries: ``` sudo apt-get install libboost-program-options-dev:amd64 sudo apt-get install libboost-program-options-dev:i386 ``` 3. When compiling, specify the library path explicitly: - For 64-bit: -L/usr/lib/x86_64-linux-gnu -lboost_program_options - For 32-bit: -L/usr/lib/i386-linux-gnu -lboost_program_options`
Camila_99$$
Camila_99$$3mo ago
Hi marvee ! Have you tried using pkg-config to auto-detect library paths? It might help avoid the conflicts between 32-bit and 64-bit Boost libraries:
g++ program.cpp -m32 $(pkg-config --cflags --libs boost_program_options) -o compiled/program.out
g++ program.cpp -m32 $(pkg-config --cflags --libs boost_program_options) -o compiled/program.out
Camila_99$$
Camila_99$$3mo ago
@Marvee Amasi But I’m curious, have you encountered any specific issues while setting up the 32-bit libraries with multilib support? Sometimes manually setting paths with -L and -I can help too, but it could be tricky depending on the library versions installed. What error messages do you get when trying this approach?
Marvee Amasi
Marvee Amasi3mo ago
Yes this g++ program.cpp -m32 $(pkg-config --cflags --libs boost_program_options) -o compiled/program.out it actually managed my dependences , all necessary libraries were included in the compilation process.
Solution
Marvee Amasi
Marvee Amasi3mo ago
Was receiving a linker error indicating that it cannot find the 32-bit Boost library, and I noticed that some of my project's dependencies might also require specific 32-bit libraries , but I was able to manage these with pkg-config . Thanks
Want results from more Discord servers?
Add your server