I am trying to compile an FLTK program (http://www.fltk.org/index.php) on Mac OSX Mavericks. All the .h packages compile just fine, but I receive the following error:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I tried both g++ and clang++ -stdlib=libstdc++ to compile the program, but received the same error both times.
I would greatly appreciate any input on this issue to eliminate this error message.
You want to use the fltk-config script but it isn't clear how to use it generally form their documentation. This is a general form that I use and what it is actually doing:
From the command line you can compile like this (this assumes you need the image libraries, opengl libraries and wish to link statically [half the point of FLTK])
g++ file1.cpp file2.cpp `fltk-config --use-forms --use-gl --use-images --ldstaticflags --cxxflags` -o output
This is equivalent to
g++ file1.cpp file2.cpp -I/usr/local/include -I/usr/local/include/FL/images -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT /usr/local/lib/libfltk_images.a /usr/local/lib/libfltk_png.a -lz /usr/local/lib/libfltk_jpeg.a /usr/local/lib/libfltk_gl.a -framework AGL -framework OpenGL -framework ApplicationServices /usr/local/lib/libfltk_forms.a /usr/local/lib/libfltk.a -lpthread -framework Cocoa -o output
So if you make sure the libraries are in /usr/local/lib and the headers in /usr/local/include that should work...
fltk-config is just a script that comes in the fltk-1.3.2 (or whatever) folder. Building FLTK from the make file should add that to your path. If not copy it or direct it to wherever it is. It does make me wonder though: have you definitely built the libraries?
This is what worked for me:
#!/bin/bash
rm ./a.out
clang++ main.cpp -o a.out -std=c++17 -stdlib=libc++ \
-I/usr/include/fltk-1.3.8/FL \
-L/usr/local/lib \
$(fltk-config --ldflags) \
&& ./a.out
Related
I'm trying to experiment around in ncurses for the first time, but I'm having problems compiling my source code. As far as I can tell, ncurses is installed and in the proper directories.
My makefile is super simple:
.cpp :
g++ -Wall -g -o $* $*.cpp -std=c++11 -lncurses
and here's my output when I try to locate ncurses.h
$ locate ncurses.h
/usr/include/ncursesw/ncurses.h
and when I check to see if it's installed
$ dpkg -l | grep ncurses
ii libncurses5:amd64 5.9+20140118-1ubuntu1 amd64 shared libraries for terminal handling
ii libncursesw5:amd64 5.9+20140118-1ubuntu1 amd64 shared libraries for terminal handling (wide character support)
ii libncursesw5-dev:amd64 5.9+20140118-1ubuntu1 amd64 developer's libraries for ncursesw
ii mtr-tiny 0.85-2 amd64 Full screen ncurses traceroute tool
ii ncurses-base 5.9+20140118-1ubuntu1 all basic terminal type definitions
ii ncurses-bin 5.9+20140118-1ubuntu1 amd64 terminal-related programs and man pages
ii ncurses-term 5.9+20140118-1ubuntu1 all additional terminal type definitions
But g++ tells me this when I try to make
bankacct.cpp:18:29: fatal error: ncurses.h: No such file or directory
compilation terminated.
Unfortunately, I've not got root access and I need to be able to compile on this machine. What are my options?
I've tried including <ncursesw/ncurses.h> based on suggestions from other users, but now g++ is giving me this error:
$ make bankacct
g++ -Wall -g -o bankacct bankacct.cpp -std=c++11 -lncurses
/usr/bin/ld: cannot find -lncurses
and if I try removing -lncurses it gives me this:
$ make bankacct
g++ -Wall -g -o bankacct bankacct.cpp -std=c++11
/tmp/cc8rPQfK.o: In function `main':
bankacct.cpp:23: undefined reference to `initscr'
Now I've tried linking the libraries. Here's what I did:
$ locate libncurse
/lib/x86_64-linux-gnu/libncurses.so.5
/lib/x86_64-linux-gnu/libncurses.so.5.9
/lib/x86_64-linux-gnu/libncursesw.so.5
/lib/x86_64-linux-gnu/libncursesw.so.5.9
/usr/lib/x86_64-linux-gnu/libncurses++w.a
/usr/lib/x86_64-linux-gnu/libncursesw.a
/usr/lib/x86_64-linux-gnu/libncursesw.so
/usr/share/doc/libncurses5
/usr/share/doc/libncursesw5
/usr/share/doc/libncursesw5-dev
/var/lib/dpkg/info/libncurses5:amd64.list
/var/lib/dpkg/info/libncurses5:amd64.md5sums
/var/lib/dpkg/info/libncurses5:amd64.postinst
/var/lib/dpkg/info/libncurses5:amd64.postrm
/var/lib/dpkg/info/libncurses5:amd64.shlibs
/var/lib/dpkg/info/libncurses5:amd64.symbols
/var/lib/dpkg/info/libncursesw5-dev:amd64.list
/var/lib/dpkg/info/libncursesw5-dev:amd64.md5sums
/var/lib/dpkg/info/libncursesw5-dev:amd64.postinst
/var/lib/dpkg/info/libncursesw5:amd64.list
/var/lib/dpkg/info/libncursesw5:amd64.md5sums
/var/lib/dpkg/info/libncursesw5:amd64.postinst
/var/lib/dpkg/info/libncursesw5:amd64.postrm
/var/lib/dpkg/info/libncursesw5:amd64.shlibs
/var/lib/dpkg/info/libncursesw5:amd64.symbols
So then I tried two variations of my makefile:
g++ -Wall -g -L/usr/lib/x86_64-linux-gnu/ -o $* $*.cpp -std=c++11 -lncurses
and
g++ -Wall -g -L/lib/x86_64-linux-gnu/ -o $* $*.cpp -std=c++11 -lncurses
which still gave me the errors undefined reference to 'initscr' (without -lncurses) or /usr/bin/ld: cannot find -lncurses (with it)
-lncurses
tells the linker to look for a library called "ncurses.". You clearly indicate that's not what your library is called:
/usr/lib/x86_64-linux-gnu/libncursesw.a
You need
-lncursesw
You don't need to modify the source code to specify <ncursesw/ncurses.h> you can simply add
-I/usr/include/ncursesw
I am writing a RecursiveASTVisitor using clang libtool.
Right now I'm trying to read in a json file and have downloaded the json library from https://github.com/open-source-parsers/jsoncpp
I have copied over the folder "include/json" to my project path "llvm/tools/clang/include"
When compiling using the ninja command, the include command isn't throwing any error include "json/json.h"
However, when I try entering a line of code Json::Value root, it throws a linking error..
Full error log:
ninja -v
[1/1] : && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Werror=date-time -std=c++11 -fcolor-diagnostics -fno-common -Woverloaded-virtual -Wno-nested-anon-types -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names tools/clang/tools/extra/myASTChecker/CMakeFiles/MyASTChecker.dir/MyASTChecker.cpp.o -o bin/MyASTChecker lib/libLLVMSupport.a lib/libclangTooling.a lib/libclangASTMatchers.a lib/libclangFormat.a lib/libclangFrontend.a lib/libclangDriver.a lib/libLLVMOption.a lib/libclangParse.a lib/libLLVMMCParser.a lib/libclangSerialization.a lib/libclangSema.a lib/libclangEdit.a lib/libclangAnalysis.a lib/libLLVMBitReader.a lib/libLLVMProfileData.a lib/libclangToolingCore.a lib/libclangAST.a lib/libclangRewrite.a lib/libclangLex.a lib/libclangBasic.a lib/libLLVMCore.a lib/libLLVMMC.a lib/libLLVMSupport.a -lcurses -lpthread -lz -lm -Wl,-rpath,#executable_path/../lib && :
FAILED: bin/MyASTChecker
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Werror=date-time -std=c++11 -fcolor-diagnostics -fno-common -Woverloaded-virtual -Wno-nested-anon-types -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names tools/clang/tools/extra/myASTChecker/CMakeFiles/MyASTChecker.dir/MyASTChecker.cpp.o -o bin/MyASTChecker lib/libLLVMSupport.a lib/libclangTooling.a lib/libclangASTMatchers.a lib/libclangFormat.a lib/libclangFrontend.a lib/libclangDriver.a lib/libLLVMOption.a lib/libclangParse.a lib/libLLVMMCParser.a lib/libclangSerialization.a lib/libclangSema.a lib/libclangEdit.a lib/libclangAnalysis.a lib/libLLVMBitReader.a lib/libLLVMProfileData.a lib/libclangToolingCore.a lib/libclangAST.a lib/libclangRewrite.a lib/libclangLex.a lib/libclangBasic.a lib/libLLVMCore.a lib/libLLVMMC.a lib/libLLVMSupport.a -lcurses -lpthread -lz -lm -Wl,-rpath,#executable_path/../lib && :
Undefined symbols for architecture x86_64:
"Json::Value::Value(Json::ValueType)", referenced from:
MyASTFrontendAction::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef) in MyASTChecker.cpp.o
"Json::Value::~Value()", referenced from:
MyASTFrontendAction::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef) in MyASTChecker.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
What am I missing or should be doing instead??
When compiling using the ninja command, the include command isn't throwing any error include "json/json.h"
When you copy paste the header files into a folder that's already in the compiler's include search path. You won't get issues in #include "json/json.h" because yeah the file is there and you haven't used anything from it yet so it's just some function, class declarations which will be ignored.
However, when I try entering a line of code Json::Value root, it throws a linking error.
Now, when wrote Json::Value root; what happened was that you called the constructor for Json::Value which is declared in the included header files, but is implemented in the source files. Hence, the compiler is not able to find that implementation of the constructor and is complaining about it.
It might have worked the whole Json parser library was implemented in the included header files. As then the compiler would have found the declaration with the definition.
What you really want to do is have the include files in the compiler's include search directory and then a compiled library file of json parser, which you link to your ASTVisitor.
Resolution:
First of all, I will discourage copy pasting json parsers include files into clang's include directory. Instead, you can do two things here:
Paste your include files in a general include directory like /usr/local/include
Add your include directory to CPLUS_INCLUDE_PATH.
Once you have that include files setup done, you will want to have the json parser from github compiled and then link your recursiveASTVisitor to it.
Answer
I see that jsonparser you linked has a cmakelist file which is really helpful if you just want to let it do the job.
once you clone the repo, do as they say to compile their library.
mkdir -p build/debug
cd build/debug
cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DARCHIVE_INSTALL_DIR=. -G "Unix Makefiles" ../..
make
After this you can call sudo make install this will copy the include files in a proper include directory which is indexed for search by your OS and also do the same for the compiled library. After this linking to your library is as simple as
CFLAGS = `pkg-config --cflags opencv`
LIBS = `pkg-config --libs opencv`
% : %.cpp
g++ $(CFLAGS) $(LIBS) -o $# $<
if you using MAKEFILE to compile your ASTVisitor (make ASTvisitor.cpp). OR
target_link_library(target jsoncpp)
if you are using a CMAKELIST to compile your ASTVisitor
Somehow my CUDA binary build process has been messed up. All of the .cu files compile nicely to .o files, but when I try to link, I get:
CMakeFiles/tester.dir/tester_intermediate_link.o: In function `__cudaRegisterLinkedBinary_66_tmpxft_00007a5f_00000000_16_cuda_device_runtime_compute_52_cpp1_ii_8b1a5d37':
/tmp/tmpxft_00006b54_00000000-2_tester_intermediate_link.reg.c:7: undefined reference to `__fatbinwrap_66_tmpxft_00007a5f_00000000_16_cuda_device_runtime_compute_52_cpp1_ii_8b1a5d37'
Now, I have not used compute_52 anywhere. My nvcc command-line is:
/usr/local/cuda/bin/nvcc -M -D__CUDACC__ /home/joeuser/src/my_project/src/kernel_specific/elementwise/Add.cu -o /home/joeuser/src/my_project/CMakeFiles/tester.dir/src/kernel_specific/elementwise/tester_generated_Add.cu.o.NVCC-depend -ccbin /usr/bin/gcc-4.9.3 -m64 --std c++11 -D__STRICT_ANSI__ -Xcompiler ,\"-Wall\",\"-g\",\"-g\",\"-O0\" -gencode arch=compute_35,code=compute_35 -g -G --generate-line-info -DNVCC -I/usr/local/cuda/include -I/opt/cub -I/usr/local/cuda/include
and my link line is:
/usr/bin/g++-4.9.3 -Wall -std=c++11 -g some.o files.o here.o blah.o blahblah.o bar.cu.o baz.cu.o -o bin/myapp -rdynamic -Wl,-Bstatic -lcudart_static -Wl,-Bdynamic -lpthread -lrt -ldl /usr/lib/libboost_system.so /usr/lib/libboost_program_options.so -Wl,-Bstatic -lcudart_static -Wl,-Bdynamic -lpthread -lrt -ldl /usr/local/cuda/extras/CUPTI/lib64/libcupti.so -lnvToolsExt -lOpenCL /usr/lib/libboost_system.so /usr/lib/libboost_program_options.so /usr/local/cuda/extras/CUPTI/lib64/libcupti.so -lnvToolsExt -lOpenCL -Wl,-rpath,/usr/lib:/usr/local/cuda/extras/CUPTI/lib64
I'll note I have separate compilation enabled, and do not seem to have skipped my intermediate link phase.
Why is this happening?
CUDA has two compilation modes, relocatable and static.
The relocatable mode is required for some configurations-which we will not get into now.
If you want to compile in relocatable mode -rdc=true, you'll need the Cuda device runtime library.
Which is located in the file cudadevrt.lib.
On some instances, supplying -lcudadevrt as a command line switch to the CUDA linker does the job, but on e.g. MSVC, you'll also need to specify cudadebrt.lib as a link dependency.
Well, I'm not sure why I'm seeing missing references to Compute 5.2 calls, but adding -lcudadevrt to the end of the link command makes the error go away.
I got following error while compiling library that computes some stuff with molecules. It is mostly academic project.
/usr/bin/ld: trajectory_manager.o: undefined reference to symbol '_ZSt24__throw_out_of_range_fmtPKcz##GLIBCXX_3.4.20'
//usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
It occurs to me that linker is trying to use some specific version of GLIBC but fails to find it or something but I am unable to find any solution to this at all.
The code was compiled using g++ (gcc version 5.3). Linker I have in version ldd (Ubuntu EGLIBC 2.19-0ubuntu6.7) 2.19. If necessary please tell me in comment section and I will provide any further information.
Edit:
Each src is compiled using:
mpiCC -pthread -ansi -Wno-long-long -g -D_DEBUG -I /home/asd/tunnel_analyzer/boost_lib/include -I ../../../src/lib -o main.o -c ../../../src/main/main.cpp
mpiCC -pthread -ansi -Wno-long-long -g -D_DEBUG -I /home/asd/tunnel_analyzer/boost_lib/include -o cache.o -c ../../../src/lib/cache.cpp
etc. and linked
mpiCC -pthread -ansi -Wno-long-long -g -D_DEBUG -I /home/asd/tunnel_analyzer/boost_lib/include -L/home/asd/tunnel_analyzer/boost_lib/lib -L. -o caverdock main.o cache.o coords.o current_weights.o everything.o grid.o szv_grid.o manifold.o model.o monte_carlo.o mutate.o my_pid.o naive_non_cache.o non_cache.o parallel_mc.o parse_pdbqt.o pdb.o quasi_newton.o quaternion.o random.o ssd.o terms.o weighted_terms.o constraint.o scheduler.o trajectory_manager.o -l boost_system -l boost_thread -l boost_serialization -l boost_filesystem -l boost_program_options
Note that mpiCC is just alias for g++.
it seems to be a G++ bug; installing libstdc++6 (4.9) apparently helps solve this.
I compiled LD_PRELOAD which uses boost (locks.hpp). Compile was successfull. I copied this LD_PRELOAD to other linux server, and when i run, error:
/usr/bin/java: symbol lookup error: /test/test.so: undefined symbol:
_ZN5boost11this_thread20disable_interruptionC1Ev
How can i fix this? Can i avoid this problem without installing boost on this server?
How i compile LD_PRELOAD:
g++ -fPIC -m32 -shared -Wl,-soname,test.so -ldl -o test.so test.cpp
Thanks!
It seems you have to get libboost_thread into your test.so file. Something along the lines of:
g++ -fPIC -m32 -shared -Wl,-soname,test.so -ldl -o test.so test.cpp \
/usr/lib/libboost_thread.a -lpthread
Since I wouldn't know the specifics for your system, the boost library might be in a different place than from mine.