Linking problems with GMP and Xcode - c++

I am trying to run a C++ project which has also dependence to PBC (https://crypto.stanford.edu/pbc/) and GMP (https://gmplib.org). I have installed PBC and GMP in the /usr/local/ directory. For this project I added the PBC (pbc-0.5.14) and GMP (gmp-6.1.0) libraries manually (I dragged those libraries into my project).
When I add the -lgmp -lgmpxx flags into Other linker flags in Xcode (Version 7.2) I got this:
ld: library not found for -lgmp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I build (and clean) without Other linker flags I got:
Undefined symbols for architecture x86_64:
"_pairing_clear", referenced from:
Member::~Member() in member.o
Manager::~Manager() in manager.o
Verifier::~Verifier() in verifier.o
"_pairing_init_set_str", referenced from:
Member::Member() in member.o
Manager::Manager() in manager.o
Verifier::Verifier() in verifier.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Did anyone know how to fix this issue or any suggestions?
Thanks.

On my Ubuntu 15.10(64), libgmp installed into
> /usr/lib/i386-linux-gnu/libgmp.so.10
> /usr/lib/i386-linux-gnu/libgmp.so.10.2.0
> /usr/lib/i386-linux-gnu/openssl-1.0.0/engines/libgmp.so
> /usr/lib/x86_64-linux-gnu/libgmp.a /usr/lib/x86_64-linux-gnu/libgmp.so
> /usr/lib/x86_64-linux-gnu/libgmp.so.10
> /usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0
> /usr/lib/x86_64-linux-gnu/libgmpxx.a
> /usr/lib/x86_64-linux-gnu/libgmpxx.so
> /usr/lib/x86_64-linux-gnu/libgmpxx.so.4
> /usr/lib/x86_64-linux-gnu/libgmpxx.so.4.4.0
I found this using command "locate libgmp". (locate searches what updatedb updates.)
You say you 'installed' it locally? I ran install without any options. Maybe your linker is not informed about where to look for the libs? Perhaps add a "-L 'local location'"?
Hope this helps ...

Related

Trying to use Boost C++ Library on MacOS

I've been trying for hours to get Boost C++ libraries working on MacOS 10.13.6.
I'm up-to-date with Xcode and Homebrew.
I used brew install boost to install boost and followed the Boost Getting Started instructions for help with compiling.
I've tried everything that I can think of and read every post I can find on StackOverflow about this.
I'm attempting to compile with:
g++ -std=c++17 -stdlib=libc++ -I /usr/local/opt/boost/include -L /usr/local/opt/boost/lib ass3.cpp -o ass3 -lboost_filesystem
and I get the following error message:
Undefined symbols for architecture x86_64: "boost::system::detail::generic_category_ncx()", referenced from: boost::system::generic_category()
in ass3-3dc386.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I haven't yet tried to install Boost from source.
If I exclude -std=c++17 the code will compile with a warning that I am using c++11 alias. As I get further into my project I'll be using c++17 specific features so I need to include this as far I as I know.
Compiler warning:
warning: alias declarations are a C++11 extension [-Wc++11-extensions]
What am I missing?

vscode g++ Link failure : Undefined symbols for architecture x86_64

Basic Info:
system: macOS High Sierra(10.13.6)
editor : vs code(latest version)
Compiler: g++ (Xcode)
Target:deploy GLFW + GLAD
Question Description:
Recently, I'm learning to do some Computer Graphics related work. Everything is going smooth. However, when i create a window to test the env.Link error happened:
Undefined symbols for architecture x86_64:
"_gladLoadGLLoader", referenced from:
_main in main-5c211c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The terminal process terminated with exit code: 1
It seems I have not link some third party file. I
have fixed exactly the same problem by add "-lglfw" args to g++ when using functions in glfw3.h.
But when meeting glad related function : gladLoadGLLoader, I don't know how to do.
Something I have done:
Can find the head file.
#include glad/glad.h
#include GLFW/glfw3.h
Have put the file "glad.c" in workspace.
Try to Add "g++ -framework XXXXX" , But doesn't work.
Try to Add "g++ -lglfw3", But doesn't work.
Add "g++ -L or I /usr/lib or /usr/local/lib or /usr/local/include", But doesn't work.
Just tell the g++ to compile glad.c by adding "glad.c" to args. I thought glad.c will be compiled by default. Although I am not clear what happened, the problem is resolved anyway.
Add glad.c into Build Phases->Compile Sources

Linker Flag/Boost not found -- linking Boost filesystem with Xcode

I am trying to the use Boost Filesystem library in Xcode.
I installed Boost with brew install boost, and it was successful.
Turns out Boost wasn't linked so I ran brew link --overwrite Boost, which worked.
I am trying to #include <boost/filesystem.hpp> in my project, but have not been successful so far.
At first Xcode couldn't find <boost/filesystem.hpp>, so I added
/usr/local/lib
/usr/local/include
to my Header search paths for Target and Project.
That fixed the original problem, but then boost_system could not be found by Xcode.
Here is the transcript:
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
___cxx_global_var_init2 in main.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init in main.o
___cxx_global_var_init1 in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I added the -lboost_system linker flag to my project, and now I am getting this error:
ld: library not found for -lboost_system
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And it's definitely the correct linker flag, so perhaps Boost installed incorrectly after all.
I will update this question if I find a solution, but I would appreciate help in solving this problem.
You only need /usr/local/include in your header search path and you need /usr/local/lib in your library search path in order for the linker to find the libraries.
Had the same problem in xcode 6 . user header search path and library search was okay . still showed link error . I solved the problem by adding -lboost_system-mt in other linker flag in project target setting

Whenever I try to link a library I get an error

I'm trying to learn FLTK for C++ and I'm working on a Macbook with the clang++ compiler. Whenever I try to link the library like this:
clang++ -L/usr/local/lib -lfltk
It gives me this error:
clang: warning: argument unused during compilation: '-X11'
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've looked on a couple other forums to see how to fix this problem and haven't gotten any answers that worked. I also tried reinstalling Command Line Tools from Apple's Developer site.
You have to make sure you put the linker command (-L/usr/local/lib -lfltk) before doing filename.cpp -o Exectuable but still in the same line in the command line.

sql::mysql::get_driver_instance() Symbol not found

I'm trying to link the mysql native API to my server software now... With little luck. When compiling in Xcode on OSX10.9 using the flags
$(OTHER_CFLAGS) -I /usr/local/boost_1_55_0/ -I
/usr/local/mysqlconn/include/ -I /usr/local/mysqlconn/lib/
I get the compiler/linker error:
Undefined symbols for architecture x86_64:
"sql::mysql::get_driver_instance()", referenced from:
sql::mysql::get_mysql_driver_instance() in SQLComm.o ld: symbol(s) not found for architecture x86_64 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
I really have no idea why though. The API files were downloaded by me today, and extracted at the included paths. I include all the files from include and include/cppconn in the server program that uses the function the linker cannot found.
Any ideas what I am doing wrong?
I see you configuring include directories, but I don't see any libraries listed there.
You need to link in the library when you build your project.