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.
Related
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
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'm trying to convert this simple makefile into a CMakeLists.txt. I'm specifically struggling with the flags.
SOURCE = triangle.cpp shader.cpp
CC = g++
CFLAGS = -Wall -Wextra -pedantic -framework OpenGL -framework GLUT -lGLEW -lglfw
OBJECT = window
default:
$(CC) -o $(OBJECT) $(SOURCE) $(CFLAGS)
clean:
rm -f $(OBJECT)
Here's my CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(Graphics)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -framework OpenGL -framework GLUT -lGLEW -lglfw")
#add_definitions(${CMAKE_CXX_FLAGS})
add_executable(
trtangle
triangle.cpp
)
Here's the error message I get:
Scanning dependencies of target triangle
[ 50%] Building CXX object CMakeFiles/triangle.dir/triangle.cpp.o
clang: warning: -framework OpenGL: 'linker' input unused [-Wunused command-line-argument]
clang: warning: -framework GLUT: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lGLEW: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lglfw: 'linker' input unused [-Wunused-command-line-argument]
/Users/neilculbertson/Desktop/OpenGL/triangle.cpp:2:10: fatal error: 'GL/glew.h' file not found
#include <GL/glew.h>
^~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/triangle.dir/triangle.cpp.o] Error 1
make[1]: *** [CMakeFiles/triangle.dir/all] Error 2
make: *** [all] Error 2
I've also tried setting CMAKE_C_FLAGS But still no luck. Keep in mind when I use the makefile alone, everything compiles and works perfectly. I'm wondering if it's a GL error? or maybe I installed GLEW weirdly?
cmake
cmake_minimum_required(VERSION 3.0) # This line is required
project(triangle) # This line is required
make
CC = g++
CFLAGS = -Wall -Wextra -pedantic -framework OpenGL -framework GLUT -lGLEW -lglfw
cmake
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -framework OpenGL -framework GLUT -lGLEW -lglfw")
make
SOURCE = triangle.cpp shader.cpp
default:
$(CC) -o $(OBJECT) $(SOURCE) $(CFLAGS)
cmake
# The name of the result and all required sources
add_executable(triangle triangle.cpp shader.cpp)
# These libraries are required
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 3.0 REQUIRED)
# ... and the path to the header files and so files
target_include_directories(triangle ${OPENGL_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS})
target_link_libraries(triangle ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} glfw3)
Other possibility is to collect all sources within a list at first.
set(SOURCES triangle.cpp shader.cpp)
add_executable(triangle ${SOURCES)
make
OBJECT = window
cmake
Not necessary
make
clean:
rm -f $(OBJECT)
cmake
This is built in.
cmake_minimum_required(VERSION 3.0)
project(Graphics)
add_executable(
trtangle
triangle.cpp
)
target_compile_options(trtangle PRIVATE -Wall -Wextra -pedantic)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 3.3 REQUIRED)
target_include_directories(trtangle ${OPENGL_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS})
target_link_libraries(trtangle ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} glfw)
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!
I am trying to re-build a simple GCC plugin (which builds fine on GNU Linux).
I am intending to compile the plugin using GNU GCC v4.6.3 which I have already installed under Mac OS X.
The Makefile contents are given below:
GCC=/Users/xxx/compilers/gcc-4.6.3/install/bin/gcc
PLUGIN_SOURCE_FILES= plugin.c
PLUGIN_OBJECT_FILES= $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
GCCPLUGINS_DIR= $(shell $(GCC) -print-file-name=plugin)
CFLAGS+= -I$(GCCPLUGINS_DIR)/include -I/Users/xxx/compilers/gcc-4.6.3/install/include - I/Users/xxx/compilers/gcc-4.6.3/gcc/ -fPIC -O0 -g3
plugin.so: $(PLUGIN_OBJECT_FILES)
$(GCC) -shared $^ -o $#
plugin.o:plugin.c
$(GCC) $(CFLAGS) -I$(GCCPLUGINS_DIR) -c $^ -o $#
clean:
rm *.o *.so
I am getting the following error:
Undefined symbols for architecture x86_64:
"_register_callback", referenced from:
_plugin_init in plugin_base.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [plugin_base.so] Error 1
GCC compiler is built using the following configuration:
../gcc-4.6.3/configure --prefix=/Users/xxx/compilers/gcc-4.6.3/install/ --program-suffix=-4.6.3.x --enable-languages=c,c++ --disable-multilib --enable-cloog-backend=isl --with-gmp=/Users/xxx/compilers/gcc-4.6.3/install/ --with-mpfr=/Users/xxx/compilers/gcc-4.6.3/install/ --with-mpc=/Users/xxx/compilers/gcc-4.6.3/install/ --with-ppl=/Users/xxx/compilers/gcc-4.6.3/install/ --with-cloog=/Users/xxx/compilers/gcc-4.6.3/install/
Had the same problem, hit this page without answers. Decided to continue digging. Found the answer on a Sourceforge page from 2008.
Instead of linking with gcc -shared ..., use gcc -dynamiclib -undefined dynamic_lookup ...
So in your example,
$(GCC) -shared $^ -o $#
should be replaced with
$(GCC) -dynamiclib -undefined dynamic_lookup $^ -o $#
Also, found that this homebrew formula was actually able to install GCC 4.6 on Mac OS X 10.10.