I try to pack my application and static link all libraries. But I get this error.The Makefile is shown below:
CC = gcc
INCPATH = -I/home/johnny/Application/FileBasedReG/include/RealityGrid
LIBS = -L/home/johnny/Application/FileBasedReG/lib/RealityGrid -lReG_Steer -l:libxml2.a -l:libncurses.a -l:libm.a -l:libz.a -l:libtermcap.a
OBJECTS = mini_steerer.o
TARGET = mini_steerer
###### Compile ######
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(INCPATH) -o $(TARGET) $(OBJECTS) $(LIBS)
mini_steerer.o: ./mini_steerer.c ./mini_steerer.h
$(CC) -c $(INCPATH) -o mini_steerer.o ./mini_steerer.c
I think I need to add one or two more static libraries, but I can't find what they are.
On a debian / ubuntu system, apt-get install liblzma-dev will do the trick. Link with -llzma.
You're probably missing the liblzma.a, which should have come as a dependency from libxml2, if you had got it from a package.
Related
I have a custom shared object file as an OpenSSL engine and it is working fine with pthread. I was trying to use a third-party thread library instead of pthread. However, upon linking and running the engine, I'm getting a Segmentation fault. I just could not figure out why. I have a hunch that my linking with the newly built dynamic library is not correct,
Following is what I did
Makefile to create a dynamic library
CC = GCC
CFLAGS = -Wall -fPIC -g -O3 -MD
LDFLAGS = -shared
OBJ = uthread.o
all: libuthread.so
libuthread.so: $(OBJ)
$(LD) -shared -o $(#) $(OBJ)
clean:
rm -f *.o *.d libuthread.so
-include *.d
%.o: %.c
$(CC) $(CFLAGS) -o $# -c $<
Copy libuthread.so library to /lib/x86_64-linux-gnu/
My Makefile to compile my OpenSSL engine
gcc -g -fPIC -c -fomit-frame-pointer testengine.c
gcc -g -shared -o libtestengine.so rsa-engine.o rsa/rsa.o rsa/bignum.o
rsa/aes.o -Wl,-Bstatic -Wl,-Bdynamic -lcrypto -luthread
mv libtestengine.so rsaEngine.so
After compilation, $ldd rsaEngine.so shows the following,
linux-vdso.so.1 => (0x00007ffded367000)
libcrypto.so.1.1 => /opt/openssl/lib/libcrypto.so.1.1 (0x00007f895c5fa000)
libuthread.so => /lib/x86_64-linux-gnu/libuthread.so (0x00007f895c3f4000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f895c02a000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f895be26000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f895bc09000)
/lib64/ld-linux-x86-64.so.2 (0x00007f895cd56000)
I use gdb to find out what causes the segmentation fault, and I find out that uthread_join(), is failing at some point. Can someone please tell me what I'm, doing wrong?
N.B: I checked the library with a simple program and the library works fine.
I just could not figure out why.
There could be a number of reasons:
A threading bug in your code (which happens not to cause a crash with system libpthread library, but causes a crash with uthread.o, whatever it is),
A bug in uthread.o which is exposed by your test, but not by the simple program you tried,
A bug somewhere else.
There is no way for us to tell with the info provided.
Your first step should be to run the program under debugger and figure out where it crashes, and then why.
I have a hunch that my linking with the newly built dynamic library is not correct
I have a hunch that your hunch is wrong. There doesn't seem to be anything wrong with your linking.
This question already has answers here:
GFortran error: ld: library not found for -lSystem when trying to compile
(9 answers)
Closed 2 years ago.
I am trying to link against the BLAS and LAPACK libraries using the makefile
FFLAGS = -O0 -fcheck=all -ffree-line-length-none
PROJECTDIR = .
srcdir = $(PROJECTDIR)/src
debug:
gfortran -c $(FFLAGS) $(srcdir)/foo.f90
gfortran -c $(FFLAGS) $(srcdir)/bar.f90
gfortran -c $(FFLAGS) $(srcdir)/foobar.f90
gfortran -o debug *.o -lblas -llapack
rm -f *.o *.mod
When I run make I get that ld: library not found for -lblas. I ran brew info openblas and saw that
openblas is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BLAS in Accelerate.framework.
For compilers to find openblas you may need to set:
export LDFLAGS="-L/usr/local/opt/openblas/lib"
export CPPFLAGS="-I/usr/local/opt/openblas/include"
So, I modified (also based on this post) the makefile to include the LDFLAGS
FFLAGS = -O0 -fcheck=all -ffree-line-length-none
LDFLAGS= -L/usr/local/opt/lapack/lib -llapack -L/usr/local/opt/openblas/lib -lblas
debug:
gfortran -c $(FFLAGS) $(srcdir)/foo.f90
gfortran -c $(FFLAGS) $(srcdir)/bar.f90
gfortran -c $(FFLAGS) $(srcdir)/foobar.f90
gfortran -o debug *.o $(LDFLAGS)
rm -f *.o *.mod
Now I get that ld: library not found for -lSystem. I also tried using the suggested Accelerate framework by using LDFLAGS = -framework Accelerate. When I did that I received that ld: framework not found Accelerate.
Any suggestions for correctly linking these libraries is greatly appreciated.
I followed the answer of Mead from this post and ran brew install gfortran and that solved the issue for me.
I installed it from source all according to boost manual with help from several discussions from stackoverflow:
1. apt-get essentials for boost
2. ./bootstrap
3. ./b2
Still getting errors, can someone tell from experience on what os examples work. I've tried to install boost for mac but there were linking errors... 1.70 boost is not necessary, maybe previous versions, I just want to try beast in my project (it was introduced in 1.66).
I m trying to build example from beast:
https://www.boost.org/doc/libs/1_70_0/libs/beast/example/advanced/server/advanced_server.cpp
Makefile:
CC=g++
CFLAGS=-pthread
LDFLAGS=
SOURCES=main.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXE=qm
all: $(SOURCES) $(EXE)
$(EXE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $#
.cpp.o:
$(CC) $(CFLAGS) $< -o $#
terminal:
g++ -pthread main.cpp -o main.o
g++ main.o -o qm
/usr/bin/ld: main.o: ZTIv: invalid version 10 (max 0)
main.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:11: recipe for target 'qm' failed
make: *** [qm] Error 1
I installed boost from source version 1.7... I've tried to search for this error without any results.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
Answer:
Just take latest examples from git repos. It helped me, good luck!
I am trying to install a project which was developed on Ubuntu, but now I am trying to make it run on Max OSX - version: 10.10.5 (Yosemite).
My current ld version that comes by default with OSX:
ld -v
#(#)PROGRAM:ld PROJECT:ld64-253.3
configured to support archs: i386 x86_64 x86_64h armv6 armv7 armv7s armv7m armv7k arm64 (tvOS)
LTO support using: LLVM version 3.7.0
Makefile contents:
PYLIB = -I/usr/include/python2.7
CLIBS =
CC = gcc
CFLAGS = $(PYLIB) $(CLIBS) -fPIC -O3 -std=c++11
LD = g++
LDFLAGS = -shared -L. -Wl,--no-as-needed $(CLIBS)
SWIG = swig
SWIGFLAGS = -c++ -python -extranative
MODULE = iPlaneImporter
CMODULE = $(MODULE).cpp
CMODULE_H = $(MODULE).h
CMODULE_OBJ = $(MODULE).o
INTERFACE = $(MODULE).i
CWRAPPER = $(MODULE)_wrap.cpp
CWRAPPER_OBJ = $(MODULE)_wrap.o
PYMODULE = $(MODULE).py
SOLIB = _$(MODULE).so
SRCS = $(CMODULE) $(CWRAPPER)
OBJS = $(CMODULE_OBJ) $(CWRAPPER_OBJ)
all: $(SOLIB) $(PYMODULE)
.PHONY: clean
clean:
rm -f $(CWRAPPER) $(PYMODULE) $(OBJS) $(SOLIB) *.pyc
$(CWRAPPER) $(PYMODULE): $(INTERFACE) $(CMODULE_H)
$(SWIG) $(SWIGFLAGS) -o $(CWRAPPER) $(INTERFACE)
$(OBJS): $(SRCS)
$(CC) -c $(SRCS) $(CFLAGS)
$(SOLIB): $(OBJS)
$(LD) $(LDFLAGS) $(OBJS) -o $(SOLIB)
Error:
ld: unknown option: --no-as-needed
collect2: error: ld returned 1 exit status
make[1]: *** [_iPlaneImporter.so] Error 1
I believe the problem here is
LDFLAGS = -shared -L. -Wl,--no-as-needed $(CLIBS)
The OSX linker doesn't support this option and I checked the man page to see what possible replacements I could use instead of --no-as-needed, but couldn't find any.
Removing that option also doesn't help - throws other errors.
I tried installing the GNU Command line tools on OSX from an online resource here. But I believe the GNU linker is not included in that.
Additionally I have also installed gcc47, doesn't help either.
Can someone please suggest some workarounds to this option and confirm that the GNU linker cannot be installed on OSX?
Thanks!
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I actualy work on a openGL projet on my VM but i need openGL 4.5 so i have install ubuntu on my laptop with (GTX 870M) who is compatible 4.5 (i check with glxinfo). But my problem is after install gcc, build-essential, libglew-dev, freeglut3-dev, freeglut3 and SDL2. I can't make my projet i have error like undefined reference on « SDL_WasInit » , « glBegin », .... for all library installed...
i try with makefile like :
ifeq "$(shell uname)" "Darwin"
LIBGL= -framework OpenGL
else
LIBGL= -lGLU -lGL
endif
CXXFLAGS += `pkg-config glew --cflags` `sdl2-config --cflags` -g -W -Wall -Wno-unused-parameter -Wno-deprecated-declarations
LDFLAGS += `pkg-config glew --libs` `sdl2-config --libs` $(LIBGL)
all : main.exe
run : main.exe
./main.exe
main.exe : main.cpp *.h
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o$# main.cpp
sol : main_solution.exe
runs : main_solution.exe
./main_solution.exe
main_solution.exe : main_solution.cpp *.h
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $# main_solution.cpp
clean :
rm -f *.o *.exe
and with cmakefile like :
cmake_minimum_required(VERSION 3.3)
project(src)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lglut -lGLU -lGL -lGLEW -lm -lSDL2 -lSDL2main -Wall -g")
set(SOURCE_FILES
"""ALL SOURCE FILES"""")
add_executable(src ${SOURCE_FILES})
This projet (cmakefile and makefile) work fine on my virtual machine ...
I hope you can help me thx.
In CMake you use target_link_libraries to specify which libraries to use. In general you want to use find_package(…) to locate the configuration for a specific library, then use the variables introduced by it to link.
find_package(OpenGL)
add_executable(foo …)
target_link_libraries(foo ${OPENGL_gl_LIBRARY} …)
You should look into the cmake modules that are used by find_package to see what the names of the variables they configure are.