I am compiling a program with the following flags and getting errors (running 64 bit os):
g++ -lm -lml -lcvaux -lhighgui -lcv -lcxcore main.o BRIEF.o -o BRIEF_demo
I get a bunch of undefined references:
main.cpp:(.text+0x1f6): undefined reference to `cvInitMatHeader'
main.cpp:(.text+0x218): undefined reference to cvInitMatHeader'
main.o: In function_Z14drawQuadrangleP9_IplImageiiiiiiii8CvScalari.constprop.77':
main.cpp:(.text+0x2d5): undefined reference to cvLine'
main.cpp:(.text+0x333): undefined reference tocvLine'
main.cpp:(.text+0x398): undefined reference to cvLine'
main.cpp:(.text+0x3f2): undefined reference tocvLine'
Anyone have an idea how to circumvent this?
I suppose you are using the newest OpenCV 2.3.x. cvInitMatHeader() and cvLine() are actually defined in libcxcore.so, which I can see you are including.
My guess is that the order of the linking is wrong, so you need to adjust your command to something like:
g++ main.cpp BRIEF.cpp -o BRIEF_demo -lm -lml -lcvaux -lhighgui -lcv -lcxcore
Related
I am trying to mix Fortran and C++ object files, which are perfectly working and producing executable with a simple C++ file. However, when I am trying to mix the same Fortran object file with the main C++ code (which is a very large and complicated code) it is producing following errors listed below. I have played with the positions of -lgfortran but no luck.
The command used is
g++ -o test *.o -static -lpthread -L/usr/local/lib -lquadmath -lgfortran
and all kind of permutations are also have been tried.
Errors are:
gcc_4_9_2_release/libgfortran/io/write_float.def:1300: undefined reference to `signbitq'
gcc_4_9_2_release/libgfortran/io/write_float.def:1300: undefined reference to `finiteq'
gcc_4_9_2_release/libgfortran/io/write_float.def:1213: undefined reference to `finiteq'
gcc_4_9_2_release/libgfortran/io/write_float.def:1300: undefined reference to `isnanq'
Working command is
g++ -static -o test *.o -lgfortran -lpthread -L/usr/local/lib -lquadmath
'nm' both the c.o and the fortran.o
I am guessing it is probably an underscore you need.
I am running Linux Mint 14.1 64-bit
I have installed the following libs:
mesa-common-dev,
freeglut3-dev,
libglew-dev
through the apt-get tool.
Here are my includes, located in my Main.h file:
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <GL/glew.h>
#include <GL/glut.h>
#include <time.h>
I checked that the libs installed correctly, they seem to be located in /usr/lib/x86_64-linux-gnu
and the headers in /usr/include/GL
I proceed to compile my Main.C file with the following flags:
g++ -Wall -Wextra -Weffc++ -Winit-self -Wmissing-include-dirs -Wswitch-default -switch-enum -Wunused-parameter -Wstrict-overflow=5 -Wfloat-equal -Wshadow -Wc++0x-compat -Wconversion -Wsign-conversion -Wmissing-declarations -Wstrict-null-sentinel -Woverloaded-virtual -Wsign-promo -Werror -pedantic -Wcast-qual -fno-pretty-templates -fmessage-length=80 -fdiagnostics-show-option -g -std=c++0x -pipe -frepo -c Main.C -o Main.o
Main.o is generated without any issues, then I try to create the binary:
g++ -I/usr/include -L/usr/lib/x86_64-linux-gnu -lGL -lglut -lGLU -lGLEW -lX11 -lm -lrt -lpng Main.o -o main
And receive the following errors:
Main.o: In function `init()':
/path/to/Main.C:12: undefined reference to `glClearColor'
Main.o: In function `initGLUT(int, char**)':
/path/to/Main.C: undefined reference to `glutInit'
/path/to/Main.C:21: undefined reference to `glutInitDisplayMode'
/path/to/Main.C:24: undefined reference to `glutInitWindowSize'
/path/to/Main.C:25: undefined reference to `glutCreateWindow'
/path/to/Main.C:28: undefined reference to `glutDisplayFunc'
/path/to/Main.C:31: undefined reference to `glutKeyboardFunc'
/path/to/Main.C:34: undefined reference to `glutMouseFunc'
/path/to/Main.C:37: undefined reference to `glutReshapeFunc'
/path/to/Main.C:40: undefined reference to `glutIdleFunc'
Main.o: In function `printFPS()':
/path/to/Main.C:96: undefined reference to `glutGet'
Main.o: In function `reshape(int, int)':
/path/to/Main.C:123: undefined reference to `glutPostRedisplay'
Main.o: In function `getTime()':
/path/to/Main.C:129: undefined reference to `glutGet'
Main.o: In function `idle()':
/path/to/Main.C:141: undefined reference to `glutPostRedisplay'
Main.o: In function `display()':
/path/to/Main.C:148: undefined reference to `glClearColor'
/path/to/Main.C:149: undefined reference to `glClear'
/path/to/Main.C:150: undefined reference to `glFlush'
/path/to/Main.C:151: undefined reference to `glutSwapBuffers'
Main.o: In function `main':
/path/to/Main.C:164: undefined reference to `glutMainLoop'
The program compiles and links on another Linux system though.
what could I be missing?
You have to pass the libraries last (after the object file)
g++ -I/usr/include -L/usr/lib/x86_64-linux-gnu Main.o \
-lGL -lglut -lGLU -lGLEW -lX11 -lm -lrt -lpng -o main
The reason behind this is, that the linker only links symbols, that are currently undefined. If you pass the libraries before the object files, then there aren't any undefined symbols to be linked and compilation/linking will therefore fail.
The libraries need to come after your object files:
g++ -I/usr/include -L/usr/lib/x86_64-linux-gnu Main.o -lGL -lglut -lGLU -lGLEW -lX11 -lm -lrt -lpng -o main
I'm updating a code from Qt3 to Qt4. I used qt3to4 porting tool, and it fixed some of my issues. But a few errors are remaining:
g++ -m64 -Wl,-O1 -o CONVECTION_DYN_CODE_version_initiale Convection_points.o Convection_points_prof.o glbox.o globjwin.o main.o algebra.o evector.o matrix.o matrix4.o quaternion.o write_binary.o write_binary_normals.o moc_glbox.o moc_globjwin.o -L/usr/lib/x86_64-linux-gnu -L/usr/X11R6/lib64 -lQtOpenGL -lQtGui -lQtCore -lGLU -lglut -lGL -lpthread -lCGAL -fp-model -lboost_thread -lgmp
glbox.o:(.rodata._ZTI7Q3GList[typeinfo for Q3GList]+0x10): undefined reference to `typeinfo for Q3PtrCollection'
&
glbox.o:(.rodata._ZTV7Q3GList[vtable for Q3GList]+0x18): undefined reference to `Q3GList::clear()'
glbox.o:(.rodata._ZTV7Q3GList[vtable for Q3GList]+0x20): undefined reference to `Q3GList::~Q3GList()'
glbox.o:(.rodata._ZTV7Q3GList[vtable for Q3GList]+0x28): undefined reference to `Q3GList::~Q3GList()'
glbox.o:(.rodata._ZTV7Q3GList[vtable for Q3GList]+0x30): undefined reference to `Q3PtrCollection::newItem(void*)'
...
Both Q3GList and Q3PtrCollection are internal classes. I added the corresponding headers but I still got these errors. I don't know how to fix it since it seems to be internal issues.
Any ideas?
You should also link against qt3support module.
Add
QT += qt3support
to your project settings.
i have already installed boost libraries with bjam install, but when i'm compiling programme:
#include boost/asio.hpp
int main()
{
return 0;
}
such errors occur:
/tmp/ccVR3eeF.o: In function `__static_initialization_and_destruction_0(int, int)':
sda.cpp:(.text+0x52): undefined reference to `boost::system::generic_category()'
sda.cpp:(.text+0x5e): undefined reference to `boost::system::generic_category()'
sda.cpp:(.text+0x6a): undefined reference to `boost::system::system_category()'
/tmp/ccVR3eeF.o: In function `boost::asio::error::get_system_category()':
sda.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[boost::asio::error::get_system_category()]+0x5): undefined reference to `boost::system::system_category()'
/tmp/ccVR3eeF.o: In function `boost::asio::detail::posix_tss_ptr_create(unsigned int&)':
sda.cpp:(.text._ZN5boost4asio6detail20posix_tss_ptr_createERj[boost::asio::detail::posix_tss_ptr_create(unsigned int&)]+0x19): undefined reference to `pthread_key_create'
/tmp/ccVR3eeF.o: In function `boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service>::context>::~posix_tss_ptr()':
sda.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_15task_io_serviceEE7contextEED2Ev[boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::task_io_service>::context>::~posix_tss_ptr()]+0x15): undefined reference to `pthread_key_delete'
/tmp/ccVR3eeF.o: In function `boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl>::context>::~posix_tss_ptr()':
sda.cpp:(.text._ZN5boost4asio6detail13posix_tss_ptrINS1_10call_stackINS1_14strand_service11strand_implEE7contextEED2Ev[boost::asio::detail::posix_tss_ptr<boost::asio::detail::call_stack<boost::asio::detail::strand_service::strand_impl>::context>::~posix_tss_ptr()]+0x15): undefined reference to `pthread_key_delete'
collect2: ld returned 1 exit status
what do i have to do? how can i build those libraries?
Boost.Asio requires the Boost.System library as well; you need to add -lboost_system to your linker command line.
As you add features to your program, you might also need other parts of Boost, like Boost.Thread, Boost.Date_Time, and so on. See http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/using.html for details.
I use netbeans so i typed '-lboost_system' in additional lines ! That was a mistake.
Additional lines are put before objects, and because of that i had the same error. Then i found out if i run from console and put -lboost_system at the VERY END everything works greate. At the end i found the right place to set in netbeans (in library not command section) and that field adds it at the end!
Remember, not only counts if you have the library in command ! THE POSITION does count :) Remember to put library at end and verify it :)
Work great:
g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -c -g -MMD -MP -MF async_client.o.d -o async_client.o async_client.cpp
g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -o async_client async_client.o -lws2_32 -lboost_chrono -lboost_system -lboost_thread
Doesn't work:
g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -c -g -MMD -MP -MF async_client.o.d -o async_client.o async_client.cpp
g++.exe -D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -lws2_32 -lboost_chrono -lboost_system -lboost_thread -o async_client async_client.o
I am in linux. My Makefile file is this
main2: main.cpp
g++ -c $(LIBS) $(CFLAGS) -fPIC main.cpp
g++ -shared main.o -o main.so
Where,
SDL_CFLAGS := $(shell sdl-config --cflags)
SDL_LDFLAGS := $(shell sdl-config --libs)
CC = gcc
COPTS = -g -Wall
CFLAGS = $(SDL_CFLAGS)
LIBS = -lstdc++ -lSDL $(SDL_LDFLAGS) -L/usr/X11R6/lib -lGL -lGLU
which runs
g++ -c -lstdc++ -lSDL -L/usr/lib -lSDL -L/usr/X11R6/lib -lGL -lGLU -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -fPIC main.cpp
g++ -shared main.o -o main.so
Now, this works without error. main.o and main.so files are produced.
However, when I try to link main.os with python ctypes
from ctypes import * import os
libtest = cdll.LoadLibrary(os.getcwd()+ '/main.so') libtest.main_loop()
libtest.main_loop()
I get this error
>>> libtest = cdll.LoadLibrary(os.getcwd() + '/main.so')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /home/atomos/DF/open_gl_client/ctypes_client/main.so: undefined symbol: glEnd
I am not sure if I am creating the linked library correctly. How do I create a linked library that I can load?
Do I have to create a .o and .os file for every library I import from main.cpp or is that taken care of automatically?
I do not understand what the compiler or linker is doing, however it works for a simple example with no imports, but for cpp files which import opengl libraries, it gives that error.
---- Update----
ldd against main.so yields
ldd main.so
linux-gate.so.1 => (0xb7755000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xaf625000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xaf5ff000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xaf4a4000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xaf485000)
/lib/ld-linux.so.2 (0xb7756000)
---- Update ----
I ran g++ without -shared flag in the second compilation step and received this error
g++ main.o -o main.so
main.o: In function `Texture_map_list::add_texture(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
main.cpp:(.text+0xf0fe): undefined reference to `glGenTextures'
main.cpp:(.text+0xf2ba): undefined reference to `glBindTexture'
main.cpp:(.text+0xf2d7): undefined reference to `glTexParameterf'
main.cpp:(.text+0xf2f4): undefined reference to `glTexParameterf'
main.cpp:(.text+0xf310): undefined reference to `glTexParameteri'
main.cpp:(.text+0xf32c): undefined reference to `glTexParameteri'
main.cpp:(.text+0xf365): undefined reference to `gluBuild2DMipmaps'
main.o: In function `init()':
main.cpp:(.text+0xf457): undefined reference to `SDL_Init'
main.cpp:(.text+0xf46d): undefined reference to `SDL_WM_SetCaption'
main.cpp:(.text+0xf472): undefined reference to `SDL_GetVideoInfo'
main.cpp:(.text+0xf480): undefined reference to `SDL_GetError'
main.cpp:(.text+0xf497): undefined reference to `SDL_Quit'
main.cpp:(.text+0xf4e2): undefined reference to `SDL_GL_SetAttribute'
main.cpp:(.text+0xf505): undefined reference to `SDL_SetVideoMode'
main.cpp:(.text+0xf513): undefined reference to `SDL_GetError'
main.cpp:(.text+0xf52a): undefined reference to `SDL_Quit'
main.cpp:(.text+0xf559): undefined reference to `glClearColor'
main.cpp:(.text+0xf565): undefined reference to `glEnable'
main.cpp:(.text+0xf571): undefined reference to `glMatrixMode'
main.cpp:(.text+0xf576): undefined reference to `glLoadIdentity'
main.cpp:(.text+0xf5a2): undefined reference to `gluPerspective'
main.o: In function `process_keypresses()':
main.cpp:(.text+0x10678): undefined reference to `SDL_PollEvent'
main.cpp:(.text+0x109a1): undefined reference to `SDL_PollEvent'
main.o: In function `main_loop':
main.cpp:(.text+0x10d76): undefined reference to `SDL_GetKeyState'
main.cpp:(.text+0x10d9f): undefined reference to `SDL_Quit'
main.o: In function `render()':
main.cpp:(.text+0x10e00): undefined reference to `SDL_GetMouseState'
main.cpp:(.text+0x10e90): undefined reference to `SDL_GetMouseState'
main.cpp:(.text+0x10f94): undefined reference to `glClear'
main.cpp:(.text+0x10fa0): undefined reference to `glMatrixMode'
main.cpp:(.text+0x10fa5): undefined reference to `glLoadIdentity'
main.cpp:(.text+0x11081): undefined reference to `gluLookAt'
main.cpp:(.text+0x11120): undefined reference to `glTranslatef'
main.cpp:(.text+0x1114d): undefined reference to `glRotatef'
main.cpp:(.text+0x1117a): undefined reference to `glRotatef'
main.cpp:(.text+0x1119e): undefined reference to `SDL_GL_SwapBuffers'
main.o: In function `draw_plane(float, float, float)':
main.cpp:(.text+0x111d8): undefined reference to `glColor3f'
main.cpp:(.text+0x111e4): undefined reference to `glBegin'
main.cpp:(.text+0x1120b): undefined reference to `glVertex3f'
....
First, note that this is easier to debug if you don't build a shared library. You are building with -shared so the linker errors don't happen until you dynamically load the library in Python. Turn off -shared while you are debugging, and you will see the errors on the command-line when you try to link:
g++ main.o -o main
main.o: In function `main':
main.cpp:(.text+0x1d): undefined reference to `glBegin'
main.cpp:(.text+0x22): undefined reference to `glEnd'
collect2: ld returned 1 exit status
Now the problem is that you are passing linker arguments to the compiler. I see that you have nicely separated CFLAGS and LIBS in the Makefile. Good. But you are passing both $(LIBS) and $(CFLAGS) on the first line, to build main.o. The LIBS will be ignored on that line, because they are link flags.
On the second line, where you are actually building the final executable, you do not pass $(LIBS), so the program is not linked with libGL or any other libraries.
Therefore, simply fix your makefile thusly:
main2: main.cpp
g++ -c $(CFLAGS) -fPIC main.cpp
g++ -shared main.o $(LIBS) -o main.so
Edit: I have since realised that in GCC, you must always put the libraries after the object files, so I have changed the last line of the makefile accordingly.
Simple:
You are passing the link flags to object compilation step.
Here is what you need:
g++ -c -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT main.cpp
g++ -lstdc++ -lSDL -L/usr/lib -lSDL -L/usr/X11R6/lib -lGL -lGLU -fPIC main.o -o main
Plus you probably don't want to create so file, but a normal executable.