Hi I'm trying to install and use GSL library following this guide: Install GSL on Mac. The brew installation works fine and I can see the file in path: /usr/local/include. Then I tried with the sample c code, but when I compile it gives me this error: symbol(s) not found for architecture x86_64. I searched and referred to this answer here: g++ error, so I added -lgsl to the command, sth like:
g++ -I/usr/local/include -lgsl main.c
But it gives: ld: library not found for -lgsl error. How can I resolve this? Thank you!
Yeah the solution should be this:
g++ -I/usr/local/include -L/usr/local/lib -lgsl main.c
This works. Refer to the answer here:Install GSL. Basically what -I gives you is the headers, while we also need the -L statement to link the library.
Related
I am trying to use the GSL library with C++ in Xcode and I was having an issue linking to the library.
I am able to link to GSL using the terminal and clang with the following linker flags
clang++ -std=c++17 -Wall -pedantic test.cpp -o test -lgsl -lgslcblas
From the command line I'm able to verify it uses the GSL library for the computation. However in Xcode, I get a "'gsl/gsl_linalg.h' file not found" error when I try to build it. Its called in my header file with
#include <gsl/gsl_linalg.h>
I added -lgsl -lgslcblas into Xcode build settings thru the "Other Linker flags" option.
I also ran
gsl-config --cflags
gsl-config --libs
and got the following output
-I/usr/local/include
-L/usr/local/lib -lgsl -lgslcblas
So it seems like GSL is installed properly and can be used by clang but for some reason when I use clang through Xcode it isn't able to use it. I was also able to manually find that particular header file in /usr/local/include/gsl/gsl_linalg.h
Any ideas on what I'm might be doing wrong?
Trying to compile code on OSX 10.15. which perfectly works on OSX 10.12 and got stuck. Quite familiar with general concept of linking and problem solving with undefined symbols as very well described here. Using command line tools only, libtool and clang++ are provided by Xcode. Seems to be a problem with my local OSX CLT chain. Tried reinstallation of full Xcode.
Compiling files with:
clang++ -g -Wall -arch x86_64 -o ./Permutation.o Permutation.cpp
clang++ -g -Wall -arch x86_64 -o ./MarchingCubes.o MarchingCubes.cpp
Then linking into shared library with:
libtool -install_name #rpath/libmodelling.dylib -dynamic -L../../../release/lib/ -lstdc++ -lpthread -lz -lm Permutation.o MarchingCubes.o -o ../../../release/lib//libmodelling.dylib
Resulting in
Undefined symbols for architecture x86_64:
"__Unwind_Resume", referenced from:
__ZN13MarchingCubesD2Ev in MarchingCubes.o
Tried several hints from similar questions on stackoverflow such as:
Setting -mmacosx-version-min=10.9, changing -lstdc++ against -lc++, trying g++ face of clang++
libunwind.dylib providing the "undefined symbol" lives in /usr/lib/system on my system which should be found via the umbrella framework System which again the compiler should figure out by himself if correctly understood.
thankful for any suggestion
If I search for files that include file libusb.h,
$grep -r "libusb.h" /usr/local/lib/
I get:
Binary file /usr/local/lib//libusb-1.0.0.dylib matches
Binary file /usr/local/lib//libusb-1.0.a matches
Binary file /usr/local/lib//libusb-1.0.dylib matches
But when I compile my class I get:
test.cpp:2:10: fatal error: 'libusb.h' file not found
#include <libusb.h>
Now I know this is because the /usr/local/lib folder isn't properly included. I tried things like the following, etc., but nothing seems to fix it.
gcc -lusb test.cpp
C_INCLUDE_PATH=/usr/local/lib
export C_INCLUDE_PATH
Update
Thanks to some of the help, I have come up with this command...
gcc test.cpp -I/usr/local/include -L/usr/local/lib -lusb-1.0
But now I get...
ld: symbol(s) not found for architecture x86_64
I tried adding
-stdlib=libstdc++
But that doesn't seem to help either.
Including the lib path won't help you here. The lib path contains the path of the binary files you link with.
You need to find the include path which provides the declarations for the exported symbols of the lib that you link against.
A common distribution (not set in stone!), is:
lib/ (binaries to link against)
include/ (declarations are here!)
bin/ (.so on *nix or .dll or Windows)
I may be beating a dead horse here. However I had the same issue and the solutions listed did not work for me. If you are in the same boat, this is what ended up working for me:
gcc -I /usr/include/libusb-1.0/ -lusb-1.0 example.c
This works...
gcc -std=c++0x -stdlib=libc++ -I/usr/local/include -L/usr/local/lib -lusb-1.0 -lstdc++ test.cpp
You can also switch to Clang. This works:
clang++ -std=c++0x -stdlib=libc++ -I/usr/local/include -L/usr/local/lib -lusb-1.0 test.cpp
See comments for more information.
I have a program that I am writing and that needs to calculate some hashes. I need SHA, MD, HMAC algorithms. That is why I chose openssl as solution.
My code is the following:
#include <openssl/md4.h>
void calc();
void calc(unsigned char* data, unsigned long len) {
unsigned char* h = new unsigned char[128];
MD4(data, len, h);
}
Compiler returns me the following:
myfile.cpp:(.text+0x3e): undefined reference to `MD4' collect2: ld
returned 1 exit status
I compile simply using:
g++ myfile.cpp -o myapp.o
under Linux Fedora.
I downloaded openssl libraries from here and compiled them cby using ./configure and then make install in the downloaded untarpalled directory. I also copied in /usr/local/include directory the include directory in the one I downloaded so that headers can be found by compiler because /usr/local/include is in my $PATH env var.
However the problem is that the linker cannot find the function. I understand that the reason might be two:
The compiler can find headers but cannot find implementations.
There are problems because openssl is written in C not in C++.
How should I proceeed? Thankyou
Edit1
I actually changed something in my openssl installation.
I installed openssl again and I could see that it places everything under /usr/local/ssl where I can find /usr/local/ssl/include and /usr/local/ssl/lib directories. I change my compilation string in:
g++ -I/usr/local/ssl/include -L/usr/local/ssl/lib -lssl -lcrypto
In the directories that I mentioned before I can find, respectively, /usr/local/ssl/include/openssl directory with all headers there and /usr/local/ssl/lib/libssl.a and /usr/local/ssl/lib/libcrypto.a libraries.
Before I did this change when I used the old compilation command, the compiler was telling me: Cannot find -lssl. With these changes, now it can find libs and headers, but ld always fails in the same way:
myfile.cpp:(.text+0x3e): undefined reference to `MD4' collect2: ld
returned 1 exit status
A little disappointed.
What do you think?
Linking against openssl usually requires -lssl.
g++ -o myapp myfile.cpp -lssl
By the way, it sounds like you may have done the installation a little incorrectly.
You shouldn't have to copy header files anywhere. And you may not have copied the shared libraries anyway.
The compilation should go something like this:
./configure --prefix=/usr/local/openssl
make
make install
And then you compile your program like:
g++ -c -o myapp1.o myfile1.cpp -I/usr/local/openssl/include
g++ -c -o myapp2.o myfile2.cpp -I/usr/local/openssl/include
g++ -o myapp myapp1.o myapp2.o -I/usr/local/openssl/include -L/usr/local/openssl/lib -lssl -lcrypto
The error is caused because you do not link the program to the openssl library during compilation.
Fix it with
g++ myfile.cpp -o myapp.o -lssl
See OpenSSL link options -lssl and -lcrypto in GCC
for how to link a program to openssl.
I am trying to compile a C++ program which invokes the ARPACK library.
My problem is that when everything is linked, some of the symbols in the ARPACK library do not get resolved. They are
__gfortran_transfer_integer
__gfortran_transfer_character
__gfortran_transfer_complex
__gfortran_compare_string
__gfortran_st_write_done
__gfortran_st_write
__gfortran_transfer_real
__gfortran_transfer_array
I did a brute force search on my lib directory, and found no library which provided all of these symbols. A couple of them are provided by libf77blas, and it looks like g95 has some similar symbols (with gfortran replaced by g95), but I am at a complete loss as to what else I might need to install. I am compiling my code with
g++-mp-4.5 -O3 -Wall -Wl,-search_paths_first -headerpad_max_install_names my.o -o my.out -L/opt/local/lib -larpack -lm -L/opt/local/lib -lgsl -lgslcblas -lm -lf77blas -llapack -larpack -lqblas -lsquack
and /opt/local/lib actually has all the libraries I reference.
Has anyone run into this problem, or can point to the solution?
add to linker -lgfortran .................