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.
Related
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.
As is asked and answered in this post, I needed to give -arch i386 option for SWIG/C# integration.
Do I need to give the option for both compilation/link?
g++ -c -arch i386 example.cxx example_wrap.cxx
g++ -arch i386 -bundle -undefined suppress -flat_namespace example.o example_wrap.o -o libexample.dylib
Have you tried it? A simple test with a C program on OS X 10.6 with a 64-bit capable machine suggests that, in general, you do need to specify -arch for both.
$ gcc -arch i386 -o x.o x.c
$ gcc x.o -o x.dylib
ld: warning: in x.o, file was built for i386 which is not the architecture being linked (x86_64)
Intuitively, the linker does need to know which set of architecture-specific libraries to link with.