I'm trying to compile a C file and I get this error:
gcc -g -ansi -pedantic -Wall -D_C_SOURCE=1 -DGC_BDW -static interp.o
scan.o utils.o main.o -L gc/.libs -lgc -lm -o joy
/usr/bin/x86_64-linux-gnu-ld: cannot find -lgc
I've already installed the Boehm-Demers-Weiser garbage collector.
Any ideas?
This is what I'm trying to compile: https://github.com/xieyuheng/joy
In joy-master/src I cloned and installed the repo of gc following this: https://github.com/ivmai/bdwgc
Related
my makefile has these entries:
build_with_dynamic: main_executable_module.o decision.o data_io.o data_stat.o data_process.so
gcc -Wall -Wextra -Werror main_executable_module.o decision.o data_io.o data_stat.o -L. data_process.so -o ../../build/program
data_process.so: data_process_fPIC.o data_stat_fPIC.o
gcc -Wall -Wextra -Werror data_process_fPIC.o data_stat_fPIC.o -shared -o data_process.so
My makefile and my shared library are located in project/src/main_module, while my executable is located in project/build
I want to create an executable in the specified folder and link it to the shared library. Currently running the executable gives me this message:
dyld: Library not loaded: data_process.so
Referenced from: /Users/user/project/build/./program
Reason: image not found
I want to become able to run the program correctly without moving anything from their current positions and only via makefile commands. I have tried this, but nothing changed:
build_with_dynamic: main_executable_module.o decision.o data_io.o data_stat.o data_process.so
gcc -Wall -Wextra -Werror main_executable_module.o decision.o data_io.o data_stat.o -L. data_process.so -Wl,-rpath,. -o ../../build/program
The program works fine if i create the executable in the same folder as the library. How should i correctly write the makefile gcc line so that i can run the program? I run the make command from the same folder the makefile is located in.
In my Makefile, I have tried build a code static linking with a library from another project I have in my computer. I have this instruction:
game: Input.o Image.o Renderer.o Surface.o Main.o
g++ -g -L ${sdl_library} -L ${lib_netpbm_library} -o release/game2d build/Input.o build/Image.o build/Renderer.o build/Surface.o build/Main.o -l:libnetpbm.a -l:libSDL2.a -l:libSDL2main.a -lGL -lGLEW -lm
It builds with no error or warning. But when I try run the generated executable, I got this error:
./game2d: error while loading shared libraries: libnetpbm.a: cannot open shared object file: No such file or directory
What I am missing here?
The issue was in fact in the way I was building the library. I change the Makefile from this:
libnetpbm: ${obj_dir}/netpbm.o ${obj_dir}/bitmap.o ${obj_dir}/graymap.o ${obj_dir}/pixmap.o
g++ -g -shared -o ${release_dir}/libnetpbm.so ${obj_dir}/netpbm.o ${obj_dir}/bitmap.o ${obj_dir}/graymap.o ${obj_dir}/pixmap.o -Wl,--out-implib,${release_dir}/libnetpbm.a
to that:
libnetpbm: ${obj_dir}/netpbm.o ${obj_dir}/bitmap.o ${obj_dir}/graymap.o ${obj_dir}/pixmap.o
ar rcs ${release_dir}/libnetpbm.a ${obj_dir}/netpbm.o ${obj_dir}/bitmap.o ${obj_dir}/graymap.o ${obj_dir}/pixmap.o
g++ -g -shared -o ${release_dir}/libnetpbm.so ${obj_dir}/netpbm.o ${obj_dir}/bitmap.o ${obj_dir}/graymap.o ${obj_dir}/pixmap.o
I'm using GCC 4.7.2 and LD 2.23 but when I add -flto to my compile options my compile time increases by over 20%! The manual seems to indicate that -fuse-linker-plugin is needed for the optimization to work. It also says that it's enabled by default with -flto but when I add it explicitly I see the following error in the link command:
g++: error: -fuse-linker-plugin is not supported in this configuration
According to manual, it should be supported by LD 2.21 or greater. Any idea why I'm getting this error? For reference here are examples of my full compile commands:
g++ -Wall -pipe -O3 -flto -fno-strict-aliasing -mtune=generic --no-exceptions -fPIC -c some.cc
g++ -o exec -Xlinker some1.o some2.o -static some1.a some2.a -Wl,--wrap,open -flto -fuse-linker-plugin
Running 'ld --help | grep plugin' shows "-plugin" option so I don't understand why GCC is complaining:
-plugin PLUGIN Load named plugin
-plugin-opt ARG Send arg to last-loaded plugin
Link time optimizations aren't supposed to reduce compilation time, but optimize runtime of your program.
#options, just add "-flto -fuse-linker-plugin" to your CFLAGS(or CXXFLAGS for c++) and LDFLAGS and it should work just fine.
#gold: ld --version is probably gonna return gnu LD, to switch to gold, make ld symlink which ld point to which ld.gold
e.g. ln -s /usr/bin/ld.gold /usr/bin/ld
I am having trouble installing pyipopt on ubuntu 12.04. During linking, I receive the error:
/usr/bin/ld: cannot find -lcoinhsl
Even though I know that this library is installed and the .so and .la files are available in /home/mostafa/MyBuilds/CoinIpopt/build/lib/
does anyone have a solution for this?
below is the complete return of running setup.py build:
root#ubuntu:~/MyBuilds/pyipopt# sudo python setup.py build
running build
running build_ext
building 'pyipopt' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/home/mostafa/MyBuilds/CoinIpopt/build/include/coin/ -I/usr/include/python2.7 -c src/callback.c -o build/temp.linux-x86_64-2.7/src/callback.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/home/mostafa/MyBuilds/CoinIpopt/build/include/coin/ -I/usr/include/python2.7 -c src/pyipopt.c -o build/temp.linux-x86_64-2.7/src/pyipopt.o
src/pyipopt.c: In function ‘set_intermediate_callback’:
src/pyipopt.c:452:15: warning: variable ‘myowndata’ set but not used [-Wunused-but-set-variable]
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relrobuild/temp.linux-x86_64-2.7/src/callback.o build/temp.linux-x86_64-2.7/src/pyipopt.o -L/home/mostafa/MyBuilds/CoinIpopt/build/lib/ -lipopt -lblas -lcoinhsl -lcoinmetis -llapack -ldl -lm -o build/lib.linux-x86_64-2.7/pyipopt.so -Wl,--rpath -Wl,/home/mostafa/MyBuilds/CoinIpopt/build/lib/
/usr/bin/ld: cannot find -lcoinhsl
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
-Ldir
Add directory dir to the list of directories to be searched for -l.
You may install your coinhsl library in one of your standard libraries directories and run 'ldconfig` before doing your ppyipopt install
I had a similar problem with another library and the reason why it didn't found it, was that I didn't run the make install (after running ./configure and make) for that library. The make install may require root privileges (in this case use: sudo make install). After running the make install you should have the so files in the correct folder, i.e. here /usr/local/lib and not in the folder mentioned by you.
you can add the Path to coinhsl lib to LD_LIBRARY_PATH variable. May be that will help.
export LD_LIBRARY_PATH=/xx/yy/zz:$LD_LIBRARY_PATH
where /xx/yy/zz represent the path to coinhsl lib.
Under gcc (g++), I have compiled a static .a (call it some_static_lib.a) library. I want to link (is that the right phrase?) this .a file into another dynamic library (call it libsomeDyn.so) that I'm building. Though the .so compiles, I don't see content of .a under .so using nm command:
/usr/bin/g++ -fPIC -g -O2 -Wall -Werror -pipe -march=pentium3
-mtune=prescott -MD -D_FILE_OFFSET_BITS=64 -DLINUX -D_GNU_SOURCE -D_THREAD_SAFE -I../../../../../../../../ -I../../../../../../../..//libraries -Wl,-rpath,/usr/lib -o libsomeDyn.so some.o another.o some_static_lib.a -shared -Wl -x
-Wl,-soname,libsomeDyn.so
I do not see functions under some_static_lib.a under libsomeDyn.so. What am I doing wrong?
Static libraries have special rules when it comes to linking. An object from the static library will only be added to the binary if the object provides an unresolved symbol.
On Linux, you can change that behavior with the --whole-archive linker option:
g++ -Wl,--whole-archive some_static_lib.a -Wl,--no-whole-archive
For every one that comes across that problem like me (and has not understand the answer properly): here is a short howto generate a dynamic library (libmylib.so) from a static one (mylib.a):
1.) create a mylib.c file that only imports the mylib.h file
2.) compile this mylib.c to mylib.o with
gcc -c -fPIC mylib.c -o mylib.o
3.) generate a dynamic library with the following command:
gcc --whole-archive -shared -Wl,-soname,libmylib.so -o libmylib.so mylib.o mylib.a
That worked at least for me, turning a static library (compiled with -fPIC) to
a dynamic library. I'm not sure wether this will work for other libraries too.