On ubuntu, I have compiled and installed all the ogre libraries. However, when I try to compile a tutorial with this command
g++ -o otest ogre.cpp -I `pkg-config --libs --cflags OGRE OIS` -lOgreMain -lOI
and it outputs
/tmp/cc9ndjXQ.o: In function `TutorialApplication::TutorialApplication()':
ogre.cpp:(.text+0xd): undefined reference to `BaseApplication::BaseApplication()'
/tmp/cc9ndjXQ.o: In function `TutorialApplication::TutorialApplication()':
ogre.cpp:(.text+0x51): undefined reference to `BaseApplication::BaseApplication()'
/tmp/cc9ndjXQ.o: In function `TutorialApplication::~TutorialApplication()':
ogre.cpp:(.text+0xc6): undefined reference to `BaseApplication::~BaseApplication()'
/tmp/cc9ndjXQ.o: In function `TutorialApplication::~TutorialApplication()':
ogre.cpp:(.text+0x13a): undefined reference to `BaseApplication::~BaseApplication()'
/tmp/cc9ndjXQ.o: In function `TutorialApplication::~TutorialApplication()':
ogre.cpp:(.text+0x1ae): undefined reference to `BaseApplication::~BaseApplication()'
/tmp/cc9ndjXQ.o: In function `main':
ogre.cpp:(.text+0x44d): undefined reference to `BaseApplication::go()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0xc): undefined reference to `BaseApplication::frameRenderingQueued(Ogre::FrameEvent const&)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x1c): undefined reference to `BaseApplication::go()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x20): undefined reference to `BaseApplication::setup()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x24): undefined reference to `BaseApplication::configure()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x28): undefined reference to `BaseApplication::chooseSceneManager()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x2c): undefined reference to `BaseApplication::createCamera()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x30): undefined reference to `BaseApplication::createFrameListener()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x38): undefined reference to `BaseApplication::destroyScene()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x3c): undefined reference to `BaseApplication::createViewports()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x40): undefined reference to `BaseApplication::setupResources()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x44): undefined reference to `BaseApplication::createResourceListener()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x48): undefined reference to `BaseApplication::loadResources()'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x4c): undefined reference to `BaseApplication::keyPressed(OIS::KeyEvent const&)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x50): undefined reference to `BaseApplication::keyReleased(OIS::KeyEvent const&)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x54): undefined reference to `BaseApplication::mouseMoved(OIS::MouseEvent const&)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x58): undefined reference to `BaseApplication::mousePressed(OIS::MouseEvent const&, OIS::MouseButtonID)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x5c): undefined reference to `BaseApplication::mouseReleased(OIS::MouseEvent const&, OIS::MouseButtonID)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x60): undefined reference to `BaseApplication::windowResized(Ogre::RenderWindow*)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x64): undefined reference to `BaseApplication::windowClosed(Ogre::RenderWindow*)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x7c): undefined reference to `non-virtual thunk to BaseApplication::windowResized(Ogre::RenderWindow*)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x84): undefined reference to `non-virtual thunk to BaseApplication::windowClosed(Ogre::RenderWindow*)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0x9c): undefined reference to `non-virtual thunk to BaseApplication::keyPressed(OIS::KeyEvent const&)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0xa0): undefined reference to `non-virtual thunk to BaseApplication::keyReleased(OIS::KeyEvent const&)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0xb4): undefined reference to `non-virtual thunk to BaseApplication::mouseMoved(OIS::MouseEvent const&)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0xb8): undefined reference to `non-virtual thunk to BaseApplication::mousePressed(OIS::MouseEvent const&, OIS::MouseButtonID)'
/tmp/cc9ndjXQ.o:(.rodata._ZTV19TutorialApplication[vtable for TutorialApplication]+0xbc): undefined reference to `non-virtual thunk to BaseApplication::mouseReleased(OIS::MouseEvent const&, OIS::MouseButtonID)'
/tmp/cc9ndjXQ.o:(.rodata._ZTI19TutorialApplication[typeinfo for TutorialApplication]+0x8): undefined reference to `typeinfo for BaseApplication'
collect2: ld returned 1 exit status
Anyone know how to fix this/what I am doing wrong?
That's not a compile time error, it's a link time error.
By the looks of things, you probably aren't compiling all the *.cpp files. What file is the body of TutorialApplication's constructor in? You need to compile and link with that.
this works on ogre tutorials :
g++ -o otest *.cpp -I `pkg-config --libs --cflags OGRE OIS`
Related
I just installed GLFW3 on Ubuntu and I'm testing the example code from the documentation (http://www.glfw.org/documentation.html) and I got those errors.
I tried multiples thing like adding -ldl, but nothing seems to work.
Here is the error log (GCC):
g++ -o bin/Debug/Game obj/Debug/main.o -ldl -lglfw3 -lm -lGL -lGLU
//usr/local/lib/libglfw3.a(vulkan.c.o): In function `_glfwInitVulkan':
vulkan.c:(.text+0x42): undefined reference to `dlopen'
vulkan.c:(.text+0xa9): undefined reference to `dlsym'
//usr/local/lib/libglfw3.a(vulkan.c.o): In function `_glfwTerminateVulkan':
vulkan.c:(.text+0x382): undefined reference to `dlclose'
//usr/local/lib/libglfw3.a(vulkan.c.o): In function `glfwGetInstanceProcAddress':
vulkan.c:(.text+0x72f): undefined reference to `dlsym'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `translateKeyCode':
x11_init.c:(.text+0x6a): undefined reference to `XkbKeycodeToKeysym'
x11_init.c:(.text+0x14a): undefined reference to `XkbKeycodeToKeysym'
x11_init.c:(.text+0x177): undefined reference to `XGetKeyboardMapping'
x11_init.c:(.text+0x191): undefined reference to `XFree'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `createKeyTables':
x11_init.c:(.text+0xc3e): undefined reference to `XkbGetMap'
x11_init.c:(.text+0xc61): undefined reference to `XkbGetNames'
x11_init.c:(.text+0x137f): undefined reference to `XkbFreeNames'
x11_init.c:(.text+0x1395): undefined reference to `XkbFreeKeyboard'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `hasUsableInputMethodStyle':
x11_init.c:(.text+0x14b2): undefined reference to `XGetIMValues'
x11_init.c:(.text+0x150c): undefined reference to `XFree'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `getSupportedAtom':
x11_init.c:(.text+0x155b): undefined reference to `XInternAtom'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `detectEWMH':
x11_init.c:(.text+0x15ea): undefined reference to `XInternAtom'
x11_init.c:(.text+0x1610): undefined reference to `XInternAtom'
x11_init.c:(.text+0x1678): undefined reference to `XFree'
x11_init.c:(.text+0x16a1): undefined reference to `XFree'
x11_init.c:(.text+0x16ad): undefined reference to `XFree'
x11_init.c:(.text+0x16be): undefined reference to `XFree'
x11_init.c:(.text+0x16ca): undefined reference to `XFree'
//usr/local/lib/libglfw3.a(x11_init.c.o):x11_init.c:(.text+0x190d): more undefined references to `XFree' follow
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x194e): undefined reference to `dlopen'
x11_init.c:(.text+0x1993): undefined reference to `dlsym'
x11_init.c:(.text+0x19c1): undefined reference to `dlsym'
x11_init.c:(.text+0x19ef): undefined reference to `dlsym'
x11_init.c:(.text+0x1a1d): undefined reference to `dlsym'
x11_init.c:(.text+0x1a8b): undefined reference to `dlopen'
x11_init.c:(.text+0x1ad0): undefined reference to `dlsym'
x11_init.c:(.text+0x1afe): undefined reference to `dlsym'
x11_init.c:(.text+0x1b56): undefined reference to `XQueryExtension'
x11_init.c:(.text+0x1bdf): undefined reference to `dlopen'
x11_init.c:(.text+0x1c24): undefined reference to `dlsym'
x11_init.c:(.text+0x1c52): undefined reference to `dlsym'
x11_init.c:(.text+0x1c80): undefined reference to `dlsym'
x11_init.c:(.text+0x1cae): undefined reference to `dlsym'
x11_init.c:(.text+0x1cdc): undefined reference to `dlsym'
//usr/local/lib/libglfw3.a(x11_init.c.o):x11_init.c:(.text+0x1d0a): more undefined references to `dlsym' follow
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x214a): undefined reference to `dlopen'
x11_init.c:(.text+0x218f): undefined reference to `dlsym'
x11_init.c:(.text+0x21bd): undefined reference to `dlsym'
x11_init.c:(.text+0x21eb): undefined reference to `dlsym'
x11_init.c:(.text+0x220d): undefined reference to `dlopen'
x11_init.c:(.text+0x2252): undefined reference to `dlsym'
x11_init.c:(.text+0x2280): undefined reference to `dlsym'
x11_init.c:(.text+0x22ae): undefined reference to `dlsym'
x11_init.c:(.text+0x23b4): undefined reference to `XkbQueryExtension'
x11_init.c:(.text+0x23f3): undefined reference to `XkbSetDetectableAutoRepeat'
x11_init.c:(.text+0x2420): undefined reference to `dlopen'
Order of libraries matter. If library A depends on library B, then A must come before B on the command line.
In your case, since the glfw3 library depends on the dl library, you must switch order so that glfw3 comes before dl on the command line.
You also must link with the X11 library.
So the full command line should look something like
g++ -o bin/Debug/Game obj/Debug/main.o -lglfw3 -ldl -lm -lGL -lGLU -lX11
I'm trying to compile a C++ program which includes the libuvc.h header file and some more header files of opencv2.
The problem is, that I'm getting the following errors (undefinded references):
root#Raspi_DataHarvest:~/Schreibtisch# g++ UVCCameraHandler.cpp -I/usr/local/include/libuvc -I/usr/local/include/opencv2
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::start(int, CameraProperties, int)':
UVCCameraHandler.cpp:(.text+0x164): undefined reference to `uvc_init'
UVCCameraHandler.cpp:(.text+0x184): undefined reference to `uvc_perror'
UVCCameraHandler.cpp:(.text+0x204): undefined reference to `uvc_get_device_descriptor'
UVCCameraHandler.cpp:(.text+0x334): undefined reference to `uvc_open'
UVCCameraHandler.cpp:(.text+0x354): undefined reference to `uvc_perror'
UVCCameraHandler.cpp:(.text+0x3a8): undefined reference to `uvc_get_stream_ctrl_format_size'
UVCCameraHandler.cpp:(.text+0x3e8): undefined reference to `uvc_get_stream_ctrl_format_size'
UVCCameraHandler.cpp:(.text+0x40c): undefined reference to `uvc_print_diag'
UVCCameraHandler.cpp:(.text+0x424): undefined reference to `uvc_print_stream_ctrl'
UVCCameraHandler.cpp:(.text+0x43c): undefined reference to `uvc_perror'
UVCCameraHandler.cpp:(.text+0x46c): undefined reference to `uvc_stream_open_ctrl'
UVCCameraHandler.cpp:(.text+0x48c): undefined reference to `uvc_stream_start_iso'
UVCCameraHandler.cpp:(.text+0x4a4): undefined reference to `uvc_perror'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::grabFramesGrayscale(cv::Mat&, cv::Mat&)':
UVCCameraHandler.cpp:(.text+0x5c8): undefined reference to `uvc_stream_get_frame'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::grabFramesColor(cv::Mat&, cv::Mat&)':
UVCCameraHandler.cpp:(.text+0x864): undefined reference to `uvc_stream_get_frame'
UVCCameraHandler.cpp:(.text+0x92c): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::uvcFindDevice(uvc_context*, uvc_device**, int, int, char const*, int)':
UVCCameraHandler.cpp:(.text+0xae0): undefined reference to `uvc_get_device_list'
UVCCameraHandler.cpp:(.text+0xb10): undefined reference to `uvc_get_device_descriptor'
UVCCameraHandler.cpp:(.text+0xd0c): undefined reference to `uvc_get_device_descriptor'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::setProperties(CameraProperties)':
UVCCameraHandler.cpp:(.text+0xfb0): undefined reference to `uvc_get_gain'
UVCCameraHandler.cpp:(.text+0xff8): undefined reference to `uvc_set_gain'
UVCCameraHandler.cpp:(.text+0x103c): undefined reference to `uvc_set_ae_mode'
UVCCameraHandler.cpp:(.text+0x1050): undefined reference to `uvc_set_exposure_abs'
UVCCameraHandler.cpp:(.text+0x1068): undefined reference to `uvc_set_ae_mode'
/tmp/ccvQZdkd.o: In function `cv::String::String(char const*)':
UVCCameraHandler.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x60): undefined reference to `cv::String::allocate(unsigned int)'
/tmp/ccvQZdkd.o: In function `cv::String::~String()':
UVCCameraHandler.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/ccvQZdkd.o: In function `cv::String::operator=(cv::String const&)':
UVCCameraHandler.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x30): undefined reference to `cv::String::deallocate()'
/tmp/ccvQZdkd.o: In function `cv::Mat::Mat(cv::Size_<int>, int, void*, unsigned int)':
UVCCameraHandler.cpp:(.text._ZN2cv3MatC2ENS_5Size_IiEEiPvj[_ZN2cv3MatC5ENS_5Size_IiEEiPvj]+0x140): undefined reference to `cv::error(int, cv::String const&, char const*, char const*, int)'
UVCCameraHandler.cpp:(.text._ZN2cv3MatC2ENS_5Size_IiEEiPvj[_ZN2cv3MatC5ENS_5Size_IiEEiPvj]+0x244): undefined reference to `cv::error(int, cv::String const&, char const*, char const*, int)'
/tmp/ccvQZdkd.o: In function `cv::Mat::~Mat()':
UVCCameraHandler.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x3c): undefined reference to `cv::fastFree(void*)'
/tmp/ccvQZdkd.o: In function `cv::Mat::operator=(cv::Mat const&)':
UVCCameraHandler.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x140): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccvQZdkd.o: In function `cv::Mat::create(int, int, int)':
UVCCameraHandler.cpp:(.text._ZN2cv3Mat6createEiii[_ZN2cv3Mat6createEiii]+0xc4): undefined reference to `cv::Mat::create(int, int const*, int)'
/tmp/ccvQZdkd.o: In function `cv::Mat::release()':
UVCCameraHandler.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x68): undefined reference to `cv::Mat::deallocate()'
/tmp/ccvQZdkd.o: In function `cv::Mat::operator()(cv::Rect_<int> const&) const':
UVCCameraHandler.cpp:(.text._ZNK2cv3MatclERKNS_5Rect_IiEE[_ZNK2cv3MatclERKNS_5Rect_IiEE]+0x24): undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)'
collect2: error: ld returned 1 exit status
So, this looks to me like g++ does not find the location of the header files, but they are installed in the correct directory!
root#Raspi_DataHarvest:~# find / | grep libuvc.h
/usr/local/include/libuvc/libuvc.h
root#Raspi_DataHarvest:~# find / | grep opencv2/opencv.hpp
/usr/local/include/opencv2/opencv.hpp
Furthermore, there's no effect using the absolute paths, like:
#include "/usr/local/include/libuvc.h"
...
Does anyone know how to solve the reference errors?
Try
g++ UVCCameraHandler.cpp -I/usr/local/include/libuvc -I/usr/local/include/opencv2 -luvc -lopencv
The most preferable
g++ UVCCameraHandler.cpp `pkg-config --libs --cflags opencv` `pkg-config --libs --cflags lubuvc`
Building a C++ program is a three-step process:
Editing the source
Compiling the source files into object files
Linking the object files into the final executable
Modern compilers often use front-end programs (like e.g. GCC with the g++ program) that combine steps 2 and 3 into a single action.
In step 2 above, the header files are included.
In step 3 you need to link with the actual libraries. You do not do this, so the linker will complain that it can't find the functions you use.
Linking with the libraries using GCC is done with the -l (lower-case L) option, listing the library name. Like for example -lopencv to link with the OpenCV library.
If the libraries are in a non-standard location (which /usr/local/lib usually is) then you need to tell the linker where to find the libraries as well. This is done with the -L option, similar to the -I option you already use to tell the compiler where to search for header-files. For example -L/usr/local/lib.
You need to link against the correct libraries (assuming your libs are in /usr/local/lib):
g++ UVCCameraHandler.cpp -I/usr/local/include/libuvc -I/usr/local/include/opencv2 -L/usr/local/lib -luvc -lopencv_core
I am taking a computer graphics course using opengl, and for the life of me, I've not been able to compile a single opengl program using the teacher's makefile without doing it on the school's server. I'm not an experience C programmer, so make files are a bit new to me. I've been spoiled by Eclipse compiler always making my build.xml file for me.
I am using cygwin since the teacher's make file is for linux/unix. I have also installed opengl on it via searching under the Graphics category on installation. This is my make file:
#!smake
# Project 1: Simple scene
#
MACHINE= $(shell uname -s)
ifeq ($(MACHINE),Darwin)
OPENGL_INC= -FOpenGL
OPENGL_LIB= -framework OpenGL -framework GLUT -framework Cocoa
else
OPENGL_INC= -I/usr/include
OPENGL_LIB= -L/usr/lib64
LLDLIBS = -lglut -lGL -lGLU -lGL -lXmu -lXext -lX11 -lm
endif
CXX=g++
COMPILER_FLAGS= -g
INCLUDE= $(OPENGL_INC)
While g++ doesn't complain about -lglut, -lGL, -lGLU, etc not existing (it was before), I still get this error message:
g++ -g -L/usr/lib64 -lglut -lGL -lGLU -lGL -lXmu -lXext -lX11 -lm MyCoolModel.o 01primitives.o 01primitivesUtil.o trackball.o model.o -o MyCoolModel
MyCoolModel.o: In function `init()':
/home/01primitives/MyCoolModel.c:48: undefined reference to `__imp_glClearColor'
/home/01primitives/MyCoolModel.c:48:(.text+0x1b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glClearColor'
/home/01primitives/MyCoolModel.c:49: undefined reference to `__imp_glShadeModel'
/home/01primitives/MyCoolModel.c:49:(.text+0x29): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glShadeModel'
/home/01primitives/MyCoolModel.c:54: undefined reference to `__imp_glGenLists'
/home/01primitives/MyCoolModel.c:54:(.text+0x41): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glGenLists'
/home/01primitives/MyCoolModel.c:58: undefined reference to `__imp_glGenLists'
/home/01primitives/MyCoolModel.c:58:(.text+0x6a): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glGenLists'
MyCoolModel.o: In function `Display()':
/home/01primitives/MyCoolModel.c:71: undefined reference to `__imp_glClear'
/home/01primitives/MyCoolModel.c:71:(.text+0xa2): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glClear'
/home/01primitives/MyCoolModel.c:73: undefined reference to `__imp_glPushMatrix'
/home/01primitives/MyCoolModel.c:73:(.text+0xab): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glPushMatrix'
/home/01primitives/MyCoolModel.c:76: undefined reference to `__imp_glDisable'
/home/01primitives/MyCoolModel.c:76:(.text+0xbe): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glDisable'
/home/01primitives/MyCoolModel.c:77: undefined reference to `__imp_glDisable'
/home/01primitives/MyCoolModel.c:77:(.text+0xcc): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glDisable'
/home/01primitives/MyCoolModel.c:80: undefined reference to `__imp_glColor3f'
/home/01primitives/MyCoolModel.c:80:(.text+0xed): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glColor3f'
/home/01primitives/MyCoolModel.c:82: undefined reference to `__imp_glBegin'
/home/01primitives/MyCoolModel.c:82:(.text+0xfb): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_glBegin'
/home/01primitives/MyCoolModel.c:83: undefined reference to `__imp_glVertex3f'
/home/01primitives/MyCoolModel.c:83:(.text+0x114): additional relocation overflows omitted from the output
/home/01primitives/MyCoolModel.c:83: undefined reference to `__imp_glVertex3f'
/home/01primitives/MyCoolModel.c:83: undefined reference to `__imp_glVertex3f'
/home/01primitives/MyCoolModel.c:84: undefined reference to `__imp_glEnd'
/home/01primitives/MyCoolModel.c:85: undefined reference to `__imp_glColor3f'
/home/01primitives/MyCoolModel.c:86: undefined reference to `__imp_glBegin'
/home/01primitives/MyCoolModel.c:87: undefined reference to `__imp_glVertex3f'
/home/01primitives/MyCoolModel.c:87: undefined reference to `__imp_glVertex3f'
/home/01primitives/MyCoolModel.c:87: undefined reference to `__imp_glVertex3f'
/home/01primitives/MyCoolModel.c:88: undefined reference to `__imp_glEnd'
/home/01primitives/MyCoolModel.c:98: undefined reference to `__imp_glCallList'
/home/01primitives/MyCoolModel.c:99: undefined reference to `__imp_glPopMatrix'
/home/01primitives/MyCoolModel.c:102: undefined reference to `__imp_glCallList'
/home/01primitives/MyCoolModel.c:107: undefined reference to `glutSwapBuffers'
MyCoolModel.o: In function `Reshape(int, int)':
/home/01primitives/MyCoolModel.c:118: undefined reference to `__imp_glViewport'
/home/01primitives/MyCoolModel.c:119: undefined reference to `__imp_glMatrixMode'
/home/01primitives/MyCoolModel.c:120: undefined reference to `__imp_glLoadIdentity'
/home/01primitives/MyCoolModel.c:121: undefined reference to `gluPerspective'
/home/01primitives/MyCoolModel.c:122: undefined reference to `__imp_glMatrixMode'
/home/01primitives/MyCoolModel.c:123: undefined reference to `__imp_glLoadIdentity'
/home/01primitives/MyCoolModel.c:124: undefined reference to `__imp_glTranslatef'
MyCoolModel.o: In function `Mouse(int, int, int, int)':
/home/01primitives/MyCoolModel.c:133: undefined reference to `glutPostRedisplay'
MyCoolModel.o: In function `Motion(int, int)':
/home/01primitives/MyCoolModel.c:139: undefined reference to `glutPostRedisplay'
MyCoolModel.o: In function `Keyboard(unsigned char, int, int)':
/home/01primitives/MyCoolModel.c:158: undefined reference to `glutPostRedisplay'
MyCoolModel.o: In function `main':
/home/01primitives/MyCoolModel.c:166: undefined reference to `glutInit'
/home/01primitives/MyCoolModel.c:167: undefined reference to `glutInitWindowPosition'
/home/01primitives/MyCoolModel.c:168: undefined reference to `glutInitWindowSize'
/home/01primitives/MyCoolModel.c:169: undefined reference to `glutInitDisplayMode'
/home/01primitives/MyCoolModel.c:170: undefined reference to `glutCreateWindow'
/home/01primitives/MyCoolModel.c:174: undefined reference to `glutDisplayFunc'
/home/01primitives/MyCoolModel.c:175: undefined reference to `glutReshapeFunc'
/home/01primitives/MyCoolModel.c:176: undefined reference to `glutMouseFunc'
/home/01primitives/MyCoolModel.c:177: undefined reference to `glutMotionFunc'
/home/01primitives/MyCoolModel.c:178: undefined reference to `glutKeyboardFunc'
/home/01primitives/MyCoolModel.c:180: undefined reference to `glutMainLoop'
01primitivesUtil.o: In function `uMakeCoordList(unsigned int)':
/home/01primitives/01primitivesUtil.c:35: undefined reference to `__imp_glNewList'
/home/01primitives/01primitivesUtil.c:37: undefined reference to `__imp_glBegin'
/home/01primitives/01primitivesUtil.c:38: undefined reference to `__imp_glColor3f'
/home/01primitives/01primitivesUtil.c:38: undefined reference to `__imp_glVertex3f'
/home/01primitives/01primitivesUtil.c:38: undefined reference to `__imp_glVertex3f'
/home/01primitives/01primitivesUtil.c:39: undefined reference to `__imp_glColor3f'
/home/01primitives/01primitivesUtil.c:39: undefined reference to `__imp_glVertex3f'
/home/01primitives/01primitivesUtil.c:39: undefined reference to `__imp_glVertex3f'
/home/01primitives/01primitivesUtil.c:40: undefined reference to `__imp_glColor3f'
/home/01primitives/01primitivesUtil.c:40: undefined reference to `__imp_glVertex3f'
/home/01primitives/01primitivesUtil.c:40: undefined reference to `__imp_glVertex3f'
/home/01primitives/01primitivesUtil.c:41: undefined reference to `__imp_glEnd'
/home/01primitives/01primitivesUtil.c:42: undefined reference to `__imp_glEndList'
01primitivesUtil.o: In function `uMakeGroundList(unsigned int)':
/home/01primitives/01primitivesUtil.c:51: undefined reference to `__imp_glNewList'
/home/01primitives/01primitivesUtil.c:53: undefined reference to `__imp_glEndList'
trackball.o: In function `_tbStopMotion(int, unsigned int)':
/home/01primitives/trackball.c:83: undefined reference to `glutIdleFunc'
/home/01primitives/trackball.c:87: undefined reference to `glutIdleFunc'
trackball.o: In function `tbInit(unsigned int)':
/home/01primitives/trackball.c:105: undefined reference to `__imp_glPushMatrix'
/home/01primitives/trackball.c:106: undefined reference to `__imp_glLoadIdentity'
/home/01primitives/trackball.c:107: undefined reference to `__imp_glGetFloatv'
/home/01primitives/trackball.c:108: undefined reference to `__imp_glPopMatrix'
trackball.o: In function `tbMatrix()':
/home/01primitives/trackball.c:117: undefined reference to `__imp_glPushMatrix'
/home/01primitives/trackball.c:118: undefined reference to `__imp_glLoadIdentity'
/home/01primitives/trackball.c:119: undefined reference to `__imp_glRotatef'
/home/01primitives/trackball.c:120: undefined reference to `__imp_glMultMatrixf'
/home/01primitives/trackball.c:121: undefined reference to `__imp_glGetFloatv'
/home/01primitives/trackball.c:122: undefined reference to `__imp_glPopMatrix'
/home/01primitives/trackball.c:124: undefined reference to `__imp_glMultMatrixf'
trackball.o: In function `tbMouse(int, int, int, int)':
/home/01primitives/trackball.c:141: undefined reference to `glutGet'
/home/01primitives/trackball.c:143: undefined reference to `glutGet'
trackball.o: In function `tbMotion(int, int, int)':
/home/01primitives/trackball.c:181: undefined reference to `glutGet'
/home/01primitives/trackball.c:187: undefined reference to `glutPostRedisplay'
trackball.o: In function `tbZoom(float)':
/home/01primitives/trackball.c:199: undefined reference to `__imp_glMatrixMode'
/home/01primitives/trackball.c:200: undefined reference to `__imp_glLoadIdentity'
/home/01primitives/trackball.c:202: undefined reference to `__imp_glTranslatef'
trackball.o: In function `translate(float, float)':
/home/01primitives/trackball.c:208: undefined reference to `__imp_glMatrixMode'
/home/01primitives/trackball.c:209: undefined reference to `__imp_glLoadIdentity'
/home/01primitives/trackball.c:214: undefined reference to `__imp_glTranslatef'
model.o: In function `ModelHead()':
/home/01primitives/model.c:18: undefined reference to `__imp_glPushMatrix'
/home/01primitives/model.c:19: undefined reference to `__imp_glTranslatef'
/home/01primitives/model.c:21: undefined reference to `__imp_glPopMatrix'
model.o: In function `ModelTorso()':
/home/01primitives/model.c:26: undefined reference to `__imp_glPushMatrix'
/home/01primitives/model.c:27: undefined reference to `__imp_glTranslatef'
/home/01primitives/model.c:28: undefined reference to `__imp_glPopMatrix'
model.o: In function `ModelUpperBody()':
/home/01primitives/model.c:33: undefined reference to `__imp_glPushMatrix'
/home/01primitives/model.c:34: undefined reference to `__imp_glTranslatef'
/home/01primitives/model.c:35: undefined reference to `__imp_glPopMatrix'
model.o: In function `ModelLegsAndFeet()':
/home/01primitives/model.c:40: undefined reference to `__imp_glPushMatrix'
/home/01primitives/model.c:41: undefined reference to `__imp_glTranslatef'
/home/01primitives/model.c:42: undefined reference to `__imp_glPopMatrix'
model.o: In function `ModelLittleMario()':
/home/01primitives/model.c:69: undefined reference to `__imp_glRasterPos2f'
/home/01primitives/model.c:70: undefined reference to `__imp_glDrawPixels'
collect2: error: ld returned 1 exit status
Makefile:36: recipe for target 'MyCoolModel' failed
make: *** [MyCoolModel] Error 1
I've been hearing that this sort of problem lies with the linker, although I'm not exactly sure what that means. I am assuming that my header files were recognized, my binaries weren't, or were in the wrong directory.
My teacher's Makefile says that the opengl library files are in a directory called /usr/lib64, but checking my cygwin user directory, it does not exist. I can see the /usr/include folder, though. This could the the problem, but I have no idea how to resolve it. I though that installing opengl on cygwin would take care of this.
Assuming that this is the problem, could anyone help me locate these library files?
I encounter g++ compile/link problem.
I want to implement a Dynamic Array.
I separated my class definition and implementation into "DArray.h" and "DArray.cpp" files.
And do test in "DArraytest.cpp" file within which contains a main functionn.
all there files are in same directory, and I use the following command to compile
g++ *.cpp
but it still gives me such link error
/tmp/cc4tu73o.o: In function __static_initialization_and_destruction_0(int, int)':
DArray.cpp:(.text+0x1d): undefined reference tostd::ios_base::Init::Init()'
DArray.cpp:(.text+0x34): undefined reference to std::ios_base::Init::~Init()'
/tmp/ccdHUZjJ.o: In functionmain':
DArraytest.cpp:(.text+0x12): undefined reference to DArray<int>::DArray()'
DArraytest.cpp:(.text+0x2e): undefined reference toDArray::append(int const&)'
DArraytest.cpp:(.text+0x4a): undefined reference to DArray<int>::append(int const&)'
DArraytest.cpp:(.text+0x66): undefined reference toDArray::append(int const&)'
DArraytest.cpp:(.text+0x82): undefined reference to DArray<int>::append(int const&)'
DArraytest.cpp:(.text+0xa3): undefined reference tostd::cout'
DArraytest.cpp:(.text+0xa8): undefined reference to std::ostream::operator<<(int)'
DArraytest.cpp:(.text+0xb0): undefined reference tostd::basic_ostream >& std::endl >(std::basic_ostream >&)'
DArraytest.cpp:(.text+0xb8): undefined reference to std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
DArraytest.cpp:(.text+0xc9): undefined reference toDArray::~DArray()'
DArraytest.cpp:(.text+0xeb): undefined reference to DArray<int>::~DArray()'
/tmp/ccdHUZjJ.o: In function__static_initialization_and_destruction_0(int, int)':
DArraytest.cpp:(.text+0x11d): undefined reference to std::ios_base::Init::Init()'
DArraytest.cpp:(.text+0x134): undefined reference tostd::ios_base::Init::~Init()'
/tmp/ccdHUZjJ.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
Can someone help me
I think you need to provide all the .cpp file names to g++. To avoid this you can create a makefile which can automatically apply same compilation rule to all .cpp files
I am trying to compile a very simple OpenGL program that uses GLFW3. Despite linking everything I deem necessary, I'm getting a plethora of undefined references.
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwInitGammaRamp':
x11_gamma.c:(.text+0x49): undefined reference to `XRRGetScreenResources'
x11_gamma.c:(.text+0x6a): undefined reference to `XRRGetCrtcGammaSize'
x11_gamma.c:(.text+0x81): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwPlatformGetGammaRamp':
x11_gamma.c:(.text+0xce): undefined reference to `XRRGetCrtcGammaSize'
x11_gamma.c:(.text+0xf1): undefined reference to `XRRGetCrtcGamma'
x11_gamma.c:(.text+0x198): undefined reference to `XRRFreeGamma'
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwPlatformSetGammaRamp':
x11_gamma.c:(.text+0x24c): undefined reference to `XRRAllocGamma'
x11_gamma.c:(.text+0x303): undefined reference to `XRRSetCrtcGamma'
x11_gamma.c:(.text+0x30f): undefined reference to `XRRFreeGamma'
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x1a67): undefined reference to `XRRQueryExtension'
x11_init.c:(.text+0x1a91): undefined reference to `XRRQueryVersion'
x11_init.c:(.text+0x1b25): undefined reference to `XIQueryVersion'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwSetVideoMode':
x11_monitor.c:(.text+0x177): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x19c): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x1be): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0x3d0): undefined reference to `XRRSetCrtcConfig'
x11_monitor.c:(.text+0x3dc): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x3e8): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x3f4): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwRestoreVideoMode':
x11_monitor.c:(.text+0x446): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x46b): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x4e0): undefined reference to `XRRSetCrtcConfig'
x11_monitor.c:(.text+0x4ec): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x4f8): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
x11_monitor.c:(.text+0x55a): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x577): undefined reference to `XRRGetOutputPrimary'
x11_monitor.c:(.text+0x5cf): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x5ea): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x659): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0x676): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x682): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x703): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x70f): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x733): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitorPos':
x11_monitor.c:(.text+0x8a2): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x8c7): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x8ff): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x90b): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetVideoModes':
x11_monitor.c:(.text+0x9ad): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x9cf): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0xb44): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0xb50): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetVideoMode':
x11_monitor.c:(.text+0xc28): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0xc4d): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0xca2): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0xcae): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_window.c.o): In function `createWindow':
x11_window.c:(.text+0x666): undefined reference to `XISelectEvents'
x11_window.c:(.text+0x6a8): undefined reference to `XRRSelectInput'
/usr/local/lib/libglfw3.a(x11_window.c.o): In function `processEvent':
x11_window.c:(.text+0x1711): undefined reference to `XRRUpdateConfiguration'
My linked CMake flags:
-I/usr/local/include -L/usr/local/lib -lglfw3 -lGLU -lGL -lGLEW
Should I be linking anything else?
I figured out the answer myself while writing the question.
I was misled into believing that I was linking everything necessary because of the output of
pkg-config --libs --cflags --print-requires glfw3
which was
-I/usr/local/include -L/usr/local/lib -lglfw3
The --print-requires flag was having no impact at all on the output, which seemed odd. I searched and printed the corresponding .pc file.
sudo find / | grep "glfw3\.pc"
cat /usr/local/lib/pkgconfig/glfw3.pc
There I found this.
Requires.private: x11 xrandr xi xxf86vm gl
Which indicates which libraries are required for static linking. I added their correponding flags to CMake and it worked. My mistake was that I missed the --print-requires-private flag when executing pkg-config.
I hope this helps someone save some time.