Compiling error with MPFR package on mac - c++

When I try to compile the newly installed package MPFR I get the following error:
Undefined symbols for architecture x86_64:
"_mpfr_init2", referenced from:
_main 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 use Codelite on a macbook pro and I think I successfully installed the package using the instruction on the website.
Any ideas on how to solve it?

From the limited information given, I suspect that you are not linking the MPFR library during the linking phase of main.cpp. What is the exact command you are using?
Make sure that -lmpfr is passed at the end of the clang++ command, like so:
clang++ main.cpp -lmpfr
or:
clang++ main.cpp -c
clang++ main.o -lmpfr
If libmpfr.so is installed in a nonstandard place, then you need to tell the compiler where, using the -L option:
clang++ main.cpp -L"$MPFR_PATH" -lmpfr
or:
clang++ main.cpp -c
clang++ main.o -L"$MPFR_PATH" -lmpfr
If not, then please provide more information.

Related

Do I need to update g++ version? If so, then how to do that?

I am working on mac system.
g++ version is "Apple clang version 12.0.0 (clang-1200.0.32.2) Target: x86_64-apple-darwin20.6.0"(I typed g++ --version).
I need to install a c++ package with command - ' $(COMPILER) $(FLAGS) <file_name>.o output.o -lm -o <file_name> '
What should I write in the place of $(FLAGS)?
This link says there is no flag for g++-12. Then, should I update the version of g++?
P.S.
Thanks who commented.
After reading all those, I tried to reinstall the package.
I know now that g++ version is 11.
I typed - 'g++ -std=c++11 <file_name>.o -lm -o <file_name>'
It worked without any error. There is a file in that folder with the name '<file_name>.o'.
After the installation (without any error) I typed - 'g++ <file1_name>.cpp -o <file1_name>' I have got an error -
Undefined symbols for architecture x86_64:
...
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So, what should I do now?

undefined symbols " __Unwind_Resume" while linking own dylib with libtool on OSX10.15

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

g++ compilation with gsl: library not found

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.

Mac OS X: clang-omp cann't find header files (xgboost installation)

I'm trying to build multithread supporting xgboost according to this guide.
So i made fist three steps. But when i run:
cd xgboost
make
i get this message:
/Users/user/clang-omp/build/bin/clang++ -c -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -fopenmp -fopenmp -fPIC -o updater.o src/tree/updater.cpp
src/tree/updater.cpp:5:10: fatal error: 'cstring' file not found
#include <cstring>
^
1 error generated.
make: *** [updater.o] Error 1
What am i doing wrong?
System:
Mac OS X 10.10.4
P.S. I've tried to set system variables like in this post, but it didn't work.
Solved:
Just found file "cstring" on my mac. There were some variants. I took folder:/usr/local/Cellar/clang-omp/2015-04-01/libexec/include/c++/v1/
and set variables:
export CPLUS_INCLUDE_PATH=/usr/local/Cellar/clang-omp/2015-04-01/libexec/include/c++/v1/:
export C_INCLUDE_PATH=/usr/local/Cellar/clang-omp/2015-04-01/libexec/include/c++/v1/:
It wasn't the end of the story. Another mistake occured:
Undefined symbols for architecture x86_64:
"__ZNKSs7compareEPKc", referenced from:
__ZN7xgboost14BoostLearnTask3RunEiPPc in main.o
__ZN7xgboost7learner12BoostLearner10InitObjGBMEv in main.o
__ZN7xgboost14BoostLearnTask8InitDataEv in main.o
...
Solved in this post.
So I just correct Makefile like this:
export CC = clang-omp++
export CXX = clang-omp++
And it's worked.

Undefined symbol __istype with /opt/local/bin/g++?

When I compile my program with this:
g++ -std=c++11 main.cpp -o run
I get this error (not sure since I don't use any code with __istype in it):
Undefined symbols for architecture x86_64:
"__istype(int, unsigned long)", referenced from:
std::ctype<char>::is(unsigned long, char) const in ccuyHAvU.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
I searched and cannot find an answer. A suggestion was to include the full path to libstdc++.a, but that did nothing:
g++ -std=c++11 main.cpp -o run /opt/local/lib/gcc48/libstdc++.a
But, when I compile with clang++ on my machine, the program does compile and work.
For this particular project, I must use g++ (the servers do not have clang++, but do have g++ v4.8). Is there anything I can do?
Edit: I tried which g++ to see where my installation of g++ is located. I then ran the command /opt/local/bin/g++ -std=c++11 main.cpp -o run, but it also ends up giving the same error.
I think you have a problem with your version glicxx, I hope this link can help you. http://psykil.livejournal.com/337476.html