I'm trying to use the Boost Libraries ... but to no avail. I attempted to follow the Getting Started tutorial on Boost's website (for Unix Variants), but having problems along the way.
I compiled the libraries into a directory in my Downloads folder:
/Users/myUsername/Downloads/boostCompiled
When I use the full path to the library ... The example program (given on the Boost Website) compiles and links fine.
g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ /Users/myUsername/Downloads/boostCompiled/lib/libboost_regex.a
However, when I attempt to link the using the -L and -l options ... it fails ...
g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ -L /Users/myUsername/Downloads/boostCompiled/lib/ -l boost_regex
ld: library not found for -lboost_regex
collect2: ld returned 1 exit status
g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ -L /Users/myUsername/Downloads/boostCompiled/lib/ -l libboost_regex
ld: library not found for -llibboost_regex
collect2: ld returned 1 exit status
g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ -L /Users/myUsername/Downloads/boostCompiled/lib/ -l regex
ld: library not found for -lregex
collect2: ld returned 1 exit status
My shell is bash ... and I've set my DYLD_LIBRARY_PATH to the following:
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:/Users/myUsername/Downloads/boostCompiled/lib
It appears I'm not using the correct name to link (with the -l) option. Can somebody please help! Thanks in advance!
There shouldn't be a space between -L and /Users/myUsername/Downloads/boostCompiled/lib/
Make sure that libboost_regex.a is compiled in /Users/myUsername/Downloads/boostCompiled/lib.
Then this should work:
g++ -o boostTesting boostTesting.cpp -I/Users/myUsername/Downloads/boostCompiled/include/ -L/Users/myUsername/Downloads/boostCompiled/lib/ -lboost_regex
Related
trying to translate this documentation https://vulkan-tutorial.com/Development_environment for getting visual studio ready to compile vulkan code to work with VS Code.
so far VS Code generates this g++ commandline (without the line breaks):
C:\Users\MYUSER\development\vulkan\MSYS2\mingw64\bin\g++.exe -fdiagnostics-color=always -g
C:\Users\MYUSER\development\vulkan\code\vulkantest.cpp -o
C:\Users\MYUSER\development\vulkan\code\vulkantest.exe
-I C:\Users\MYUSER\development\vulkan\glfw-3.3.7.bin.WIN64\include
-I C:\Users\MYUSER\development\vulkan\glm-0.9.9.8\
-I C:\Users\MYUSER\development\vulkan\vulkan_sdk-1.3.204.1\Include\
-L C:\Users\MYUSER\development\vulkan\vulkan_sdk-1.3.204.1\Lib
-L C:\Users\MYUSER\development\vulkan\glfw-3.3.7.bin.WIN64\lib-vc2022
now in the screenshots from the link above they "add" glfw3.lib and vulkan1.lib, adding just glfw3.lib like this does not work:
C:\Users\MYUSER\development\vulkan\MSYS2\mingw64\bin\g++.exe -fdiagnostics-color=always -g C:\Users\MYUSER\development\vulkan\code\vulkantest.cpp -o C:\Users\MYUSER\development\vulkan\code\vulkantest.exe -I C:\Users\MYUSER\development\vulkan\glfw-3.3.7.bin.WIN64\include -I C:\Users\MYUSER\development\vulkan\glm-0.9.9.8\ -I C:\Users\MYUSER\development\vulkan\vulkan_sdk-1.3.204.1\Include\ -L C:\Users\MYUSER\development\vulkan\vulkan_sdk-1.3.204.1\Lib -L C:\Users\MYUSER\development\vulkan\glfw-3.3.7.bin.WIN64\lib-vc2022 -lglfw3.lib C:/Users/MYUSER/development/vulkan/MSYS2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lglfw3.lib: No such file or directory collect2.exe: error: ld returned 1 exit status
this file:
"C:\Users\MYUSER\development\vulkan\glfw-3.3.7.bin.WIN64\lib-vc2022\glfw3.dll"
does exist.
how do you add that library in windows/VS Code?
When I execute this command
g++ -L/home/andrea/Desktop/cppTest/Test1/myLib -I/home/andrea/Desktop/cppTest/Test1/commons -lNames compiledObjects/SayHello.o -o SayHello
The compiler return this error:
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lNames
collect2: error: ld returned 1 exit status
Why the compiler search "Names" here
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld
instead of
/home/andrea/Desktop/cppTest/Test1/myLib
That is the path specified using -L argmunt?
Problem found
The real problem was that I've forgotten to name the library in this way libName.so
The right syntax is as follows
g++ -I/home/andrea/Desktop/cppTest/Test1/commons compiledObjects/SayHello.o -o SayHello -L/home/andrea/Desktop/cppTest/Test1/myLib -lNames
(i.e. -L and -l options at the end).
And ensure that the directory /home/andrea/Desktop/cppTest/Test1/ contains the library libNames.so.
I am trying to link a project with the following command:
g++ build/test.o -o bin/test -pthread -L lib -L /home/alexander/opt/lib -lboost_thread-mt
which results in the following errors:
/usr/bin/ld: cannot find -lboost_thread-mt
collect2: error: ld returned 1 exit status
However, the boost libraries are installed in the directory /home/alexander/opt/lib. Why does the linker do not find the boost libraries? I also tried to link with -I instead if -L with the same outcome...
Content of /home/alexander/opt/lib is /home/alexander/opt/lib/boost_1_57_0.
change libboost_thread-mt to libboost_thread, first find the address of libboost_thread.so and libboost_thread.a then make softlinks to these files in the same address,
so it should be:
ln -s /...libboostSourceFiles.../libboost_thread.so /..RequestTOmtFiles.../libboost_thread-mt.so
it works for other libboost -mt files too, like serialization , iostreams, programoptions
I try to crosscompile this small program to my arm device, but get error:
arm-none-linux-gnueabi/bin/ld: cannot find -lasound
collect2: error: ld returned 1 exit status
Then i found libasound files in my target device and have copied to my folder /usr/lib but still no effect.
I use the commands:
export CFLAGS="-I/usr/include -I/usr/lib"
$CC -o play sound_playback.c $CFLAGS -lasound
I have installed libasound2-dev package on my Ubuntu 14.04 x64 and be able to compile the program on my native computer without any errors.
UPDATE WITH SOLUTION
As Marc and John have said below, i just should use -L flag to set my library path. So my command line should be:
$CC -o play sound_playback.c $CFLAGS -L/usr/lib -lasound
I am compiling a C++ application using GNU g++. The project takes advantage of OpenSSL libraries.
Background
On my machine (a 64 bit CentOS quad core) I compile and link my files.
g++ -g -c -L/usr/local/lib/ -L/usr/lib64/
-I/usr/local/include/ -I/usr/local/ssl/include/
-lcrypto mysrc1.cpp mysrc2.cpp mysrc3.cpp
g++ -L/usr/local/lib/ -L/usr/lib64/ -lcrypto
*.o -o ./myapp.out
My application uses function MD5 which is contained in libcrypto.so. As you can see I specify to g++ the dirs where to search using the -L, -I options and which libraries to look for with the -l<lib-name> option. There are some trivial paths like /usr/local/lib which can be omitted of course, but I specified them because the makefile is parametric.
The problem
My problem is that I can successfully compile my stuff (first command), but linking fails (second command):
/usr/bin/ld: cannot find -lcrypto
collect2: ld returned 1 exit status
make: * [cppsims_par] Error 1
But I did check folders and everything... libcrypto.so is inside /usr/lib64/. What is going on?
It may help if you try strace to find why it failed the file lookup
strace -f -e trace=file g++ -L/usr/local/lib/ -L/usr/lib64/ -lcrypto
*.o -o ./myapp.out
I did find the problem and it is related to this question: ld cannot find an existing library
Actually I had no symlink libcrypto.so and the compiler was not able to find the library...
I had related issue, and resolved it after inspecting the trace.
I had
-L<my/path/to/lib> -llib_some_library
when it should have been
-L<my/path/to/lib> -lsome_library