I am trying to compile a .so file the relies on the FTDI library. I'm not sure how to include the library so that it compiles correctly. (Below is my best guess). Is this possible or is there another way to go about it?
shared: pldevice pldeviceenttecpro pluniverse
$(CC) -shared -Wl,-soname,libplanklight.so -o libplanklight.so\
-L/usr/local/lib -lftd2xx \
pldevice.o pldeviceenttecpro.o pluniverse.o
Edit: This is what the output is:
g++ -fPIC -c pldevice.cpp
g++ -fPIC -c pldeviceenttecpro.cpp
g++ -fPIC -c pluniverse.cpp
g++ -shared -Wl,-soname,libplanklight.so -o libplanklight.so\
-L/usr/local/lib -lftd2xx \
pldevice.o pldeviceenttecpro.o pluniverse.o
/usr/bin/x86_64-linux-gnu-ld: cannot open output file libplanklight.so-L/usr/local/lib: No such file or directory
collect2: error: ld returned 1 exit status
Makefile:5: recipe for target 'shared' failed
make: *** [shared] Error 1
You're missing a space.
$(CC) -shared -Wl,-soname,libplanklight.so -o libplanklight.so \
^^
Add a space here
The \ just makes the command continue on the next line, so when you have
-o libplanklight.so\
-L/usr/local/lib
It will be the same as -o libplanklight.so-L/usr/local/lib
But you want -o libplanklight.so -L/usr/local/lib
Related
I'm running make and ld will not find libraries that I have verified to exist using dnf provides '*/libpthread.so' for example. I get the following error code:
g++ -fopenmp -static -lpthread -o bayescan_2.1 start.o beta.o dirichlet.o RJupdates.o MHupdates.o likelihood.o read_write.o anyoption.o
/bin/ld: cannot find -lpthread
/bin/ld: cannot find -lm
/bin/ld: cannot find -ldl
/bin/ld: cannot find -lpthread
/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
make: *** [Makefile:4: bayescan_2.1] Error 1
These libraries all are found in /usr/lib64 on my chair's computing cluster. However the ld.so.conf file does not include a path that only goes to /usr/lib64 and I don't have admin permissions to create a new .conf file in /etc/ld.so.conf.d/.
Is there any way I can force make to search for the libraries in /usr/lib64?
Here is the actual Makefile in question:
# BayeScan makefile
bayescan_2.1: start.o beta.o dirichlet.o RJupdates.o MHupdates.o likelihood.o read_write.o anyoption.o
g++ -fopenmp -static -lpthread -o bayescan_2.1 start.o beta.o dirichlet.o RJupdates.o MHupdates.o likelihood.o read_write.o anyoption.o
start.o: start.cpp errors.cpp anyoption.h global_defs.h
g++ -fopenmp -c start.cpp errors.cpp
beta.o: beta.cpp global_defs.h
g++ -fopenmp -c beta.cpp
dirichlet.o: dirichlet.cpp global_defs.h
g++ -fopenmp -c dirichlet.cpp
RJupdates.o: RJupdates.cpp global_defs.h
g++ -fopenmp -c RJupdates.cpp
MHupdates.o: MHupdates.cpp global_defs.h
g++ -fopenmp -c MHupdates.cpp
likelihood.o: likelihood.cpp global_defs.h
g++ -fopenmp -c likelihood.cpp
read_write.o: read_write.cpp errors.cpp global_defs.h
g++ -fopenmp -c read_write.cpp errors.cpp
anyoption.o: anyoption.cpp anyoption.h
g++ -fopenmp -c anyoption.cpp
clean:
rm *.o bayescan_2.1
EDIT:
Turns out ld was trying to find static libraries with the -static flag. Removing this flag from the Makefile fixed the issue.
Simply add -L/usr/lib64 to the link command. See Directory Options in the GCC manual:
-Ldir
Add directory dir to the list of directories to be searched for -l.
If you can't or don't want to edit the Makefile, you can supply additional search directories through an environment variable
LIBRARY_PATH
The value of LIBRARY_PATH is a colon-separated list of directories, much like PATH. When configured as a native compiler, GCC tries the directories thus specified when searching for special linker files, if it cannot find them using GCC_EXEC_PREFIX. Linking using GCC also uses these directories when searching for ordinary libraries for the -l option (but directories specified with -L come first).
For example, run this in your shell before invoking make:
$ export LIBRARY_PATH="$LIBRARY_PATH:/usr/lib64"
This is my first time using makefile. I am getting "linker command failed with exit code 1 " error while using "clang".
I just linked .h files in makefile and run make all in ubuntu teminal.
CC_EXEC = clang
CC_FLAGS = -g
CC = ${CC_EXEC} ${CC_FLAGS}
BUILD_DIR = build
all: executable.out
executable.out: ${BUILD_DIR}/main.o ${BUILD_DIR}/UTrelloInterface.o ${BUILD_DIR}/User.o ${BUILD_DIR}/List.o ${BUILD_DIR}/Task.o
clang -g ${BUILD_DIR}/main.o ${BUILD_DIR}/UTrelloInterface.o ${BUILD_DIR}/User.o ${BUILD_DIR}/List.o ${BUILD_DIR}/Task.o -o ${BUILD_DIR}/executable.out
${BUILD_DIR}/main.o: main.cpp UTrelloInterface.h User.h List.h Task.h
${CC} -c main.cpp -o ${BUILD_DIR}/main.o
${BUILD_DIR}/User.o: User.cpp User.h
${CC} -c User.cpp -o ${BUILD_DIR}/User.o
${BUILD_DIR}/List.o: List.cpp List.h
${CC} -c List.cpp -o ${BUILD_DIR}/List.o
${BUILD_DIR}/Task.o: Task.cpp Task.h
${CC} -c Task.cpp -o ${BUILD_DIR}/Task.o
${BUILD_DIR}/UTrelloInterface.o: UTrelloInterface.cpp UTrelloInterface.h Task.h List.h User.h
${CC} -c UTrelloInterface.cpp -o ${BUILD_DIR}/UTrelloInterface.o
.PHONY: clean
clean:
rm -rf build/ && mkdir -p build
I got exactly this error:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
makefile:11: recipe for target 'executable.out' failed
make: *** [executable.out] Error 1
I got this error while using g++ compiler:
g++ -g -c User.cpp -o build/User.o
g++ -g build/main.o build/UTrelloInterface.o build/User.o build/List.o build/Task.o -o build/executable.out
/usr/bin/ld: build/main.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
makefile:11: recipe for target 'executable.out' failed
make: *** [executable.out] Error 1
What should I do?
I am trying to compile a wallet for my JUMP coins (https://github.com/Jumperbillijumper/jumpcoin).
I cloned the repo,
cd to src/
and ran $ make -f makefile.unix
and now I am getting this error:
/home/pi/jumpcoin/jumpcoin/src/leveldb/libmemenv.a: error addingsymbols: Archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status
makefile.unix:206: recipe for target 'jumpcoind' failed
make: *** [jumpcoind] Error 1
Log:
pi#Raspberry_Pi:~/jumpcoin/jumpcoin/src $ make -f makefile.unix
/bin/sh ../share/genbuild.sh obj/build.h
g++ -c -O2 -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -g -DBOOST_SPIRIT_THREADSAFE -I/home/pi/jumpcoin/jumpcoin/src -I/home/pi/jumpcoin/jumpcoin/src/obj -DUSE_UPNP=0 -DUSE_IPV6=1 -I/home/pi/jumpcoin/jumpcoin/src/leveldb/include -I/home/pi/jumpcoin/jumpcoin/src/leveldb/helpers -DHAVE_BUILD_INFO -fno-stack-protector -fstack-protector-all -Wstack-protector -D_FORTIFY_SOURCE=2 -MMD -MF obj/txdb-leveldb.d -o obj/txdb-leveldb.o txdb-leveldb.cpp
g++ -O2 -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -g -DBOOST_SPIRIT_THREADSAFE -I/home/pi/jumpcoin/jumpcoin/src -I/home/pi/jumpcoin/jumpcoin/src/obj -DUSE_UPNP=0 -DUSE_IPV6=1 -I/home/pi/jumpcoin/jumpcoin/src/leveldb/include -I/home/pi/jumpcoin/jumpcoin/src/leveldb/helpers -DHAVE_BUILD_INFO -fno-stack-protector -fstack-protector-all -Wstack-protector -D_FORTIFY_SOURCE=2 -o jumpcoind obj/groestl.o obj/blake.o obj/skein.o obj/keccak.o obj/jh.o obj/alert.o obj/version.o obj/checkpoints.o obj/netbase.o obj/addrman.o obj/crypter.o obj/key.o obj/db.o obj/init.o obj/irc.o obj/keystore.o obj/miner.o obj/main.o obj/net.o obj/protocol.o obj/jumpcoinrpc.o obj/rpcdump.o obj/rpcnet.o obj/rpcmining.o obj/rpcwallet.o obj/rpcblockchain.o obj/rpcrawtransaction.o obj/script.o obj/sync.o obj/util.o obj/wallet.o obj/walletdb.o obj/noui.o obj/kernel.o obj/pbkdf2.o obj/scrypt.o obj/scrypt-arm.o obj/scrypt-x86.o obj/scrypt-x86_64.o obj/zerocoin/Accumulator.o obj/zerocoin/AccumulatorProofOfKnowledge.o obj/zerocoin/Coin.o obj/zerocoin/CoinSpend.o obj/zerocoin/Commitment.o obj/zerocoin/ParamGeneration.o obj/zerocoin/Params.o obj/zerocoin/SerialNumberSignatureOfKnowledge.o obj/zerocoin/SpendMetaData.o obj/zerocoin/ZeroTest.o obj/txdb-leveldb.o -Wl,-z,relro -Wl,-z,now -Wl,-Bdynamic -l boost_system -l boost_filesystem -l boost_program_options -l boost_thread -l db_cxx -l ssl -l crypto -l miniupnpc -Wl,-Bdynamic -l z -l dl -l pthread /home/pi/jumpcoin/jumpcoin/src/leveldb/libleveldb.a /home/pi/jumpcoin/jumpcoin/src/leveldb/libmemenv.a
/home/pi/jumpcoin/jumpcoin/src/leveldb/libmemenv.a: error adding symbols: Archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status
makefile.unix:206: recipe for target 'jumpcoind' failed
make: *** [jumpcoind] Error 1
ok the problem was in the src/leveldb directory (obviously)
I took the src/leveldb directory from this repo (https://github.com/sagacrypto/SagaCoin) and replaced the current one. Then everything works fine. (at least for me :P)
yeah I know it is not best practice but this one was driving me nuts :D
I'm following this SDL tutorial to try and make use of some SDL extension libraries. My code is identical to theirs but I am still unable to make the file which leads me to believe the problem is in my makefile which looks like this:
CXX = g++
# Update these paths to match your installation
# You may also need to update the linker option rpath, which sets where to look for
# the SDL2 libraries at runtime to match your install
SDL_LIB = -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image
SDL_INCLUDE = -I/usr/local/include
# You may need to change -std=c++11 to -std=c++0x if your compiler is a bit older
CXXFLAGS = -Wall -c -std=c++11 $(SDL_INCLUDE)
LDFLAGS = $(SDL_LIB)
EXE = SDL_Lesson3
all: $(EXE)
$(EXE): main.o
$(CXX) $< $(LDFLAGS) -o $#
main.o: main.cpp
$(CXX) $(CXXFLAGS) $< -o $#
clean:
rm *.o && rm $(EXE)
That makefile worked fine for previous examples. The only thing that has changed in this example is line 5 where I added -lSDL2_image as per the tutorial. When I try make the file I get the following traceback:
rony#comet:~/Documents/cpp/helloworld/lesson3$ make
g++ main.o -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image -o SDL_Lesson3
/usr/bin/ld: cannot find : No such file or directory
collect2: error: ld returned 1 exit status
make: *** [SDL_Lesson3] Error 1
Is there an error with my makefile? Have I not installed the library correctly?
The problem is this rogue comma:
SDL_LIB = -L/usr/local/lib -lSDL2 -Wl,-rpath=/usr/local/lib, -lSDL2_image
^
causing the linker to look for libraries in a non-existent directory with an empty name, as well as /usr/local/lib. Removing the comma should fix it.
I have a project that is a library that links against libresolv,
It works fine on recent distros: Ubuntu 10.x Fedora 13, Mandriva
2010.1 but on Centos 5.x I get the following errors
glibc installed is: glibc-2.5-18.el5_1.1
g++ -DHAVE_CONFIG_H -I. -I./include -I/usr/include/postgresql -O3
-ansi -Wall -Wno-deprecated -D_FORTIFY_SOURCE=0 -MT testUpLog.o -MD
-MP -MF .deps/testUpLog.Tpo -c -o testUpLog.o testUpLog.cc
mv -f .deps/testUpLog.Tpo .deps/testUpLog.Po
/bin/sh ./libtool --tag=CXX --mode=link g++ -O3 -ansi -Wall
-Wno-deprecated -D_FORTIFY_SOURCE=0 -L/usr/lib64 -L/lib64
-L/usr/lib64/mysql -o testUpLog testUpLog.o libUpTools.la -lpq
-lmysqlclient -lssl -lpthread
libtool: link: g++ -O3 -ansi -Wall -Wno-deprecated -D_FORTIFY_SOURCE=0
-o .libs/testUpLog testUpLog.o -L/usr/lib64 -L/lib64
-L/usr/lib64/mysql ./.libs/libUpTools.so -lpq -lmysqlclient -lssl
-lpthread
./.libs/libUpTools.so: undefined reference to `__ns_name_uncompress'
./.libs/libUpTools.so: undefined reference to `__ns_initparse'
./.libs/libUpTools.so: undefined reference to `__ns_parserr'
collect2: ld returned 1 exit status
make[1]: *** [testUpLog] Error 1
make[1]: Leaving directory `/tmp/UpTools-8.5.3'
make: *** [check-am] Error 2
library.la file contains:
dlname='libUpTools.so.0'
library_names='libUpTools.so.0.0.0 libUpTools.so.0 libUpTools.so'
old_library='libUpTools.a'
inherited_linker_flags=''
dependency_libs=' -L/usr/lib64 -L/lib64 -L/usr/lib64/mysql -lpq
-lmysqlclient -lssl -lpthread'
weak_library_names=''
current=0
age=0
revision=0
installed=no
shouldnotlink=no
dlopen=''
dlpreopen=''
libdir='/usr/lib'
You can read configure.ac on
http://pastebin.com/hs5q21Rq
Thanks in advance
If libUpTools uses functions lib libresolv, you need to say so:
libUpTools_la_LIBADD = -lresolv (of course -lresolv may be replaced by variables determined by configure etc.)
That way, -lresolv will end up in the .la file and also in the .so file (if you chose to build it) that you can run ldd on for verification.