I'm trying to build a little utility program that relies upon GraphicsMagick C++ library but I got the following error when linking to the library:
make all-recursive
make[1]: Entering directory `/home/ale/sample'
Making all in src
make[2]: Entering directory `/home/ale/sample/src'
g++ -g -O2 -o mysample mysample-a.o -L/usr/local/lib -lexiv2 -L/usr/local/lib -lGraphicsMagick++ -lGraphicsMagick
/usr/local/lib/libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o): In function `png_put_data':
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1171: undefined reference to `png_get_io_ptr'
/usr/local/lib/libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o): In function `PNGWarningHandler':
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1357: undefined reference to `png_error'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1361: undefined reference to `png_get_error_ptr'
/usr/local/lib/libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o): In function `PNGErrorHandler':
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1338: undefined reference to `png_get_error_ptr'
/usr/local/lib/libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o): In function `png_get_data':
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1060: undefined reference to `png_get_io_ptr'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1076: undefined reference to `png_warning'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1077: undefined reference to `png_error'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:1067: undefined reference to `png_warning'
/usr/local/lib/libGraphicsMagick.a(magick_libGraphicsMagick_la-png.o): In function `png_write_raw_profile':
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6243: undefined reference to `png_malloc'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6253: undefined reference to `png_malloc'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6254: undefined reference to `png_malloc'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6281: undefined reference to `png_set_text'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6282: undefined reference to `png_free'
/home/ale/Downloads/GraphicsMagick-1.3.18/coders/png.c:6283: undefined reference to `png_free'
Why does the library in /usr/local/lib refers to GraphicsMagick source code (that I've built and installed)?
Errors says that you need to link with libpng too.
You having very descriptive source-code related errors because you've built graphicsmagick with debugging symbols. In release build (or if you'll strip debugging symbols out of debug build) you'll see only undefined function names, without source code references of where they're being used.
Related
I am finding trouble linking a library in C++.
I am trying for the first time to use "matplotlibcpp.h". This is a library that uses "Python.h"
My code is not using either of the libraries yet. It gives error just by including "matplotlibcpp". I am using python2.7 and Ubuntu 18.04 and am using Eclipse.
The code does not run if I include:
#include "matplotlibcpp.h" // programme runs if this is commented out. But I need it to add new features.
#include "Python.h"
I have added these paths in several futile attempts (they solved similar issues to other threads):
GCC C++ Compiler, include paths (-l)
/home/toni/Programs/Workspace/Libraries/matplotlib-cpp-master/
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy
/usr/include/python2.7
GCC C++ Linker, Library search path (-L)
/home/toni/Programs/Workspace/Libraries/matplotlib-cpp-master/
/usr/lib/python2.7/config-i386-linux-gnu
/usr/lib/python2.7
/usr/include/python2.7
The programme builds, but does not run:
Finished building: ../src/WindProfilesCoursera.cpp
Building target: WindProfilesCoursera
Invoking: GCC C++ Linker
g++ -L/home/toni/Programs/Workspace/Libraries/matplotlib-cpp-master/ -L/usr/lib/python2.7/config-i386-linux-gnu -L/usr/lib/python2.7 -L/usr/include/python2.7 -o "WindProfilesCoursera" ./src/WindProfilesCoursera.o
./src/WindProfilesCoursera.o: In function `_import_array':
/usr/include/python2.7/numpy/__multiarray_api.h:1456: undefined reference to `PyImport_ImportModule'
makefile:45: recipe for target 'WindProfilesCoursera' failed
/usr/include/python2.7/numpy/__multiarray_api.h:1460: undefined reference to `PyExc_ImportError'
/usr/include/python2.7/numpy/__multiarray_api.h:1460: undefined reference to `PyErr_SetString'
/usr/include/python2.7/numpy/__multiarray_api.h:1463: undefined reference to `PyObject_GetAttrString'
/usr/include/python2.7/numpy/__multiarray_api.h:1466: undefined reference to `PyExc_AttributeError'
/usr/include/python2.7/numpy/__multiarray_api.h:1466: undefined reference to `PyErr_SetString'
/usr/include/python2.7/numpy/__multiarray_api.h:1478: undefined reference to `PyCObject_Type'
/usr/include/python2.7/numpy/__multiarray_api.h:1479: undefined reference to `PyExc_RuntimeError'
/usr/include/python2.7/numpy/__multiarray_api.h:1479: undefined reference to `PyErr_SetString'
/usr/include/python2.7/numpy/__multiarray_api.h:1483: undefined reference to `PyCObject_AsVoidPtr'
/usr/include/python2.7/numpy/__multiarray_api.h:1487: undefined reference to `PyExc_RuntimeError'
/usr/include/python2.7/numpy/__multiarray_api.h:1487: undefined reference to `PyErr_SetString'
/usr/include/python2.7/numpy/__multiarray_api.h:1493: undefined reference to `PyExc_RuntimeError'
/usr/include/python2.7/numpy/__multiarray_api.h:1493: undefined reference to `PyErr_Format'
/usr/include/python2.7/numpy/__multiarray_api.h:1499: undefined reference to `PyExc_RuntimeError'
/usr/include/python2.7/numpy/__multiarray_api.h:1499: undefined reference to `PyErr_Format'
/usr/include/python2.7/numpy/__multiarray_api.h:1511: undefined reference to `PyExc_RuntimeError'
/usr/include/python2.7/numpy/__multiarray_api.h:1511: undefined reference to `PyErr_Format'
/usr/include/python2.7/numpy/__multiarray_api.h:1522: undefined reference to `PyExc_RuntimeError'
/usr/include/python2.7/numpy/__multiarray_api.h:1522: undefined reference to `PyErr_Format'
collect2: error: ld returned 1 exit status
make: *** [WindProfilesCoursera] Error 1
"make all" terminated with exit code 2. Build might be incomplete.
20:35:04 Build Failed. 22 errors, 1 warnings. (took 2s.454ms)
I've been trying to compile this OpenGL tutorial (originally purposed for Visual Studio) but I keep having 'undefined reference' errors. The compiler output is as follows:
Info: Internal Builder is used for build
g++ -o OpenGLTutorial.exe "src\\main.o" "src\\Camera.o" -lglew32 -lglu32 -lopengl32 -lfreeglut
src\main.o: In function `Z6InitGLiPPc':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:75: undefined reference to `glutInit'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:76: undefined reference to `glutSetOption'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:77: undefined reference to `glutGet'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:78: undefined reference to `glutGet'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:80: undefined reference to `glutInitDisplayMode'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:82: undefined reference to `glutInitContextVersion'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:83: undefined reference to `glutInitContextProfile'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:84: undefined reference to `glutInitContextFlags'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:86: undefined reference to `glutInitWindowPosition'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:87: undefined reference to `glutInitWindowSize'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:89: undefined reference to `glutCreateWindow'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:91: undefined reference to `glutIdleFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:92: undefined reference to `glutDisplayFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:93: undefined reference to `glutKeyboardFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:94: undefined reference to `glutKeyboardUpFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:95: undefined reference to `glutSpecialFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:96: undefined reference to `glutSpecialUpFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:97: undefined reference to `glutMouseFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:98: undefined reference to `glutMotionFunc'
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:99: undefined reference to `glutReshapeFunc'
src\main.o: In function `main':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:236: undefined reference to `glutMainLoop'
src\main.o: In function `Z9ReshapeGLii':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:249: undefined reference to `glutPostRedisplay'
src\main.o: In function `Z9DisplayGLv':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:262: undefined reference to `glutSwapBuffers'
src\main.o: In function `Z6IdleGLv':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:278: undefined reference to `glutPostRedisplay'
src\main.o: In function `Z10KeyboardGLhii':
C:\Users\jordanrich\Documents\programming\C++\GameDev\OpenGLTutorial\Debug/../src/main.cpp:313: undefined reference to `glutLeaveMainLoop'
collect2.exe: error: ld returned 1 exit status
21:39:05 Build Finished (took 1s.154ms)
Can anyone tell me what is wrong?
If you need any more information to help answer the question just ask.
Edit (Some additional info):
As you can see from the compiler output I have linked the library that these functions require and the compiler does not complain that it could not find said library. Also I placed the freeglut dll into the binary folder.
This problem was apparently mainly due to user error and was completely circumstantial. I'm posting this for the people of the future who might have this problem.
In my header file I defined FREEGLUT_STATIC. After changing this to another variable, the linker no longer produced errors. Though I can't actually check -- very easily at least -- somewhere in my freeglut library this variable was used in an ifndef statement to determine whether freeglut needed to be linked (in case it was already linked).
I need to call some methods from a C++ program in a C program.
But I just have one shared library (.dll) to use those methods.
To make it, first a create a wrapper in C to call the methods from the dll to be used in the C program. I have attention and I make sure that I declare the functions with extern "C" to avoid name mangling.
But when a compile I have a set of errors (shown in down) when a linking wall the .o's:
g++ -o bonnie++ bonnie++.o bon_io.o bon_file.o bon_time.o semaphore.o sync.o thread.o bon_suid.o duration.o rand.o util.o utils.o super.o pcm_file.o inode.o iname.o dir.o pcm.o -lpthread -L./ -lSmart
pcm.o:pcm.c:(.text+0x4d): undefined reference to `_imp___ZN10Management11OpenEm'
pcm.o:pcm.c:(.text+0x64): undefined reference to `_imp___ZN10Management12CloseEm'
pcm.o:pcm.c:(.text+0x73): undefined reference to `_imp___ZN10Management17EnumerateEv'
pcm.o:pcm.c:(.text+0xb9): undefined reference to `_imp___ZN18DemonstratorDevC1Ev'
pcm.o:pcm.c:(.text+0xf7): undefined reference to `_imp___ZN18DemonstratorDevD1Ev'
pcm.o:pcm.c:(.text+0x121): undefined reference to `_imp___ZN18DemonstratorDevice11OpenEi'
pcm.o:pcm.c:(.text+0x138): undefined reference to `_imp___ZN18DemonstratorDev12CloseAdapterEv'
pcm.o:pcm.c:(.text+0x15f): undefined reference to `_imp___ZN18DemonstratorDev23ConfigureClockFrequencyEi15_ClockFrequency'
pcm.o:pcm.c:(.text+0x176): undefined reference to `_imp___ZN18DemonstratorDev21AdaptationBlockEnableEv'
pcm.o:pcm.c:(.text+0x1a1): undefined reference to `_imp___ZN18CommandsManagementC1ER18DemonstratorDev'
pcm.o:pcm.c:(.text+0x1df): undefined reference to `_imp___ZN18CommandsManagementD1Ev'
pcm.o:pcm.c:(.text+0x21a): undefined reference to `_imp___ZN18CommandsManagement20DeviceInitializationEim9TimerCtrl'
pcm.o:pcm.c:(.text+0x253): undefined reference to `_imp___ZN18CommandsManagement24EnableEmbeddedOperationsER8OWStatusim9TimerCtrl'
pcm.o:pcm.c:(.text+0x290): undefined reference to `_imp___ZN18CommandsManagement12RegionUnlockEmmim9TimerCtrl'
pcm.o:pcm.c:(.text+0x2da): undefined reference to `_imp___ZN18CommandsManagement17BufferedOverwriteEmmPKhiiim9TimerCtrl'
pcm.o:pcm.c:(.text+0x32c): undefined reference to `_imp___ZN18CommandsManagement9BurstReadEmPtmih9BurstTypeim9TimerCtrl'
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../i686-pc-cygwin/bin/ld: pcm.o: bad reloc address 0x20 in section `.eh_frame$_ZN10ManagementC1Ev'
collect2: error: ld returned 1 exit status
Makefile:37: recipe for target `bonnie++' failed
make: *** [bonnie++] Error 1
Someone know what I am doing wrong?
Do you include the extern "C" function declaration header files in your wrapper method source file? if not, this error will occur
I am driving nuts....
I'm working on a program to read out Joint Coordinates from an Xtion Primesense sensor with OpenNI and NiTE. I got the program splittet in 3 parts. Main, sensorOpenNI.hpp and sensorOpenNI.cpp. Now while linking the parts together I get lots of errors saying there are undefined references to some NiTE functions. I'm working with Kubuntu and g++. The NiTE and OpenNI libs are in a directory called Include...
Here's the error message:
/tmp/ccrPQHEg.o: In function openni::VideoFrameRef::release()':
sensorOpenNI.cpp:(.text._ZN6openni13VideoFrameRef7releaseEv[openni::VideoFrameRef::release()]+0x18): undefined reference tooniFrameRelease'
/tmp/ccrPQHEg.o: In function openni::VideoFrameRef::_setFrame(OniFrame*)':
sensorOpenNI.cpp:(.text._ZN6openni13VideoFrameRef9_setFrameEP8OniFrame[openni::VideoFrameRef::_setFrame(OniFrame*)]+0x25): undefined reference tooniFrameAddRef'
/tmp/ccrPQHEg.o: In function nite::UserTrackerFrameRef::release()':
sensorOpenNI.cpp:(.text._ZN4nite19UserTrackerFrameRef7releaseEv[nite::UserTrackerFrameRef::release()]+0x24): undefined reference toniteUserTrackerFrameRelease'
/tmp/ccrPQHEg.o: In function nite::UserTracker::create(openni::Device*)':
sensorOpenNI.cpp:(.text._ZN4nite11UserTracker6createEPN6openni6DeviceE[nite::UserTracker::create(openni::Device*)]+0x13): undefined reference toniteInitializeUserTracker'
sensorOpenNI.cpp:(.text._ZN4nite11UserTracker6createEPN6openni6DeviceE[nite::UserTracker::create(openni::Device*)]+0x27): undefined reference to niteInitializeUserTrackerByDevice'
/tmp/ccrPQHEg.o: In functionnite::UserTracker::destroy()':
sensorOpenNI.cpp:(.text._ZN4nite11UserTracker7destroyEv[nite::UserTracker::destroy()]+0x1e): undefined reference to niteShutdownUserTracker'
/tmp/ccrPQHEg.o: In functionnite::UserTracker::readFrame(nite::UserTrackerFrameRef*)':
sensorOpenNI.cpp:(.text._ZN4nite11UserTracker9readFrameEPNS_19UserTrackerFrameRefE[nite::UserTracker::readFrame(nite::UserTrackerFrameRef*)]+0x1d): undefined reference to niteReadUserTrackerFrame'
/tmp/ccrPQHEg.o: In functionnite::UserTracker::startSkeletonTracking(short)':
sensorOpenNI.cpp:(.text._ZN4nite11UserTracker21startSkeletonTrackingEs[nite::UserTracker::startSkeletonTracking(short)]+0x1e): undefined reference to niteStartSkeletonTracking'
/tmp/ccrPQHEg.o: In functionnite::NiTE::initialize()':
sensorOpenNI.cpp:(.text._ZN4nite4NiTE10initializeEv[nite::NiTE::initialize()]+0x7): undefined reference to niteInitialize'
collect2: ld returned 1 exit status
patrick#ubuntu:~/Koerpersteuerung$ g++ -c sensorOpenNI.cpp sensorOpenNI.hpp -I Include/
patrick#ubuntu:~/Koerpersteuerung$ g++ mainSensor.cpp sensorOpenNI.o -I Include/
sensorOpenNI.o: In functionopenni::VideoFrameRef::release()':
sensorOpenNI.cpp:(.text._ZN6openni13VideoFrameRef7releaseEv[openni::VideoFrameRef::release()]+0x18): undefined reference to oniFrameRelease'
sensorOpenNI.o: In functionopenni::VideoFrameRef::_setFrame(OniFrame*)':
sensorOpenNI.cpp:(.text._ZN6openni13VideoFrameRef9_setFrameEP8OniFrame[openni::VideoFrameRef::_setFrame(OniFrame*)]+0x25): undefined reference to oniFrameAddRef'
sensorOpenNI.o: In functionnite::UserTrackerFrameRef::release()':
sensorOpenNI.cpp:(.text._ZN4nite19UserTrackerFrameRef7releaseEv[nite::UserTrackerFrameRef::release()]+0x24): undefined reference to niteUserTrackerFrameRelease'
sensorOpenNI.o: In functionnite::UserTracker::create(openni::Device*)':
sensorOpenNI.cpp:(.text._ZN4nite11UserTracker6createEPN6openni6DeviceE[nite::UserTracker::create(openni::Device*)]+0x13): undefined reference to niteInitializeUserTracker'
sensorOpenNI.cpp:(.text._ZN4nite11UserTracker6createEPN6openni6DeviceE[nite::UserTracker::create(openni::Device*)]+0x27): undefined reference toniteInitializeUserTrackerByDevice'
sensorOpenNI.o: In function nite::UserTracker::destroy()':
sensorOpenNI.cpp:(.text._ZN4nite11UserTracker7destroyEv[nite::UserTracker::destroy()]+0x1e): undefined reference toniteShutdownUserTracker'
sensorOpenNI.o: In function nite::UserTracker::readFrame(nite::UserTrackerFrameRef*)':
sensorOpenNI.cpp:(.text._ZN4nite11UserTracker9readFrameEPNS_19UserTrackerFrameRefE[nite::UserTracker::readFrame(nite::UserTrackerFrameRef*)]+0x1d): undefined reference toniteReadUserTrackerFrame'
sensorOpenNI.o: In function nite::UserTracker::startSkeletonTracking(short)':
sensorOpenNI.cpp:(.text._ZN4nite11UserTracker21startSkeletonTrackingEs[nite::UserTracker::startSkeletonTracking(short)]+0x1e): undefined reference toniteStartSkeletonTracking'
sensorOpenNI.o: In function nite::NiTE::initialize()':
sensorOpenNI.cpp:(.text._ZN4nite4NiTE10initializeEv[nite::NiTE::initialize()]+0x7): undefined reference toniteInitialize'
collect2: ld returned 1 exit status
I'm calling g++ like this:
g++ -o test mainSensor.cpp sensorOpenNI.cpp -I Include/
Try copying the libraries libOpenNI2.so and libNiTE2 like that:
sudo cp ./OpenNI-Linux-x86-2.2/Redist/libOpenNI2.so /usr/local/lib
sudo cp ./NiTE-Linux-x86-2.2/Redist/libNiTE2.so /usr/local/lib
then do
sudo ldconfig
and now compile the program by adding -lOpenNI2 -lNiTE2
I have an application, with dynamic linking all ok, but when i trying to compile with static linking, i have errors below.
My app uses boost thread, asio
Error:
/tmp/ccMj2fHI.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x237): undefined reference to `boost::system::get_system_category()'
test.cpp:(.text+0x243): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x24f): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x25b): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x267): undefined reference to `boost::system::get_system_category()'
/tmp/ccnCWj1O.o: In function `__static_initialization_and_destruction_0(int, int)':
AccountSe.cpp:(.text+0x507): undefined reference to `boost::system::get_system_category()'
AccountSe.cpp:(.text+0x513): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x51f): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x52b): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x537): undefined reference to `boost::system::get_system_category()'
And similar errors for all source files.
Compile command line:
g++ -L /usr/lib/ -lboost_system -lboost_thread -o newserver -static
/usr/lib/libboost_thread.a /usr/lib/libboost_system.a stdafx.cpp
test.cpp AccountSe.cpp ... -lpthread -std=c++0x
It mostly likely is due to your linking order. Boost libraries appear first in the command line, and after processing them, the linker, will discard unreferenced symbols before proceeding to link other object files and libraries.
Put boost libraries after your sources and before -lpthread.