c++ compilation error- undefined reference - c++

My cpp file has Scilab and Octave header files. I'm trying to compile using this command
g++ -l:/usr/lib/scilab/libscilab.so -L/usr/lib/scilab -L/usr/lib/scilab -I/usr/include/octave-3.8.1 -I/usr/include/octave-3.8.1/octave -I/usr/include/scilab s_o_test_v4.cpp -o s_o_test_v4
I get the following error
s_o_test_v4.cpp:(.text+0x5f4): undefined reference to `pvApiCtx'
s_o_test_v4.cpp:(.text+0x5ff): undefined reference to `isVarMatrixType'
s_o_test_v4.cpp:(.text+0x61a): undefined reference to `pvApiCtx'
s_o_test_v4.cpp:(.text+0x644): undefined reference to `getMatrixOfDouble'
s_o_test_v4.cpp:(.text+0x743): undefined reference to `string_vector::c_str_vec() const'
s_o_test_v4.cpp:(.text+0x755): undefined reference to `octave_main'
s_o_test_v4.cpp:(.text+0x7a2): undefined reference to `octave_value::octave_value(double)'
s_o_test_v4.cpp:(.text+0x847): undefined reference to `feval(std::string const&, octave_value_list const&, int)'
s_o_test_v4.cpp:(.text+0x8a3): undefined reference to `pvApiCtx'
Both Scilab and Octave functions show error. Should I include or remove something from my compile command?

Maybe the ordering of your make command is wrong, see also
this SO question:
Please also note that libraries need to be specified on the command
line after the files needing them
That would make your command:
g++ -I/usr/include/octave-3.8.1 -I/usr/include/octave-3.8.1/octave -I/usr/include/scilab s_o_test_v4.cpp -o s_o_test_v4 -l:/usr/lib/scilab/libscilab.so -L/usr/lib/scilab -L/usr/lib/scilab

Related

Eclipse, MinGW, Freeglut undefined reference

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).

How can do I link libevent that has been configured to have a different prefix?

I am trying to link libevent using g++ but am having trouble since I set libevent's install directory with the --prefix flag when configuring. To install libevent I downloaded the latest source, extracted it and ran the following commands in the directory
./configure --prefix=/home/tom/local --disable-shared && make
make install
After running these commands libevent successfully installs to the /home/tom/local folder. Now to test that I can use libevent I have downloaded the sample rot13 server with libevent that can be found towards the bottom of: http://www.wangafu.net/~nickm/libevent-book/01_intro.html
To compile I run the following command:
g++ -I=/home/tom/local/include rot13server.cpp -L/home/tom/local/lib
But I get the following compilation errors:
/tmp/cctwJY4k.o: In function `alloc_fd_state(event_base*, int)':
libevent.cc:(.text+0x9b): undefined reference to `event_new'
libevent.cc:(.text+0xec): undefined reference to `event_new'
libevent.cc:(.text+0x11a): undefined reference to `event_free'
/tmp/cctwJY4k.o: In function `free_fd_state(fd_state*)':
libevent.cc:(.text+0x1b6): undefined reference to `event_free'
libevent.cc:(.text+0x1c9): undefined reference to `event_free'
/tmp/cctwJY4k.o: In function `do_read(int, short, void*)':
libevent.cc:(.text+0x310): undefined reference to `event_add'
/tmp/cctwJY4k.o: In function `do_write(int, short, void*)':
libevent.cc:(.text+0x4da): undefined reference to `event_del'
/tmp/cctwJY4k.o: In function `do_accept(int, short, void*)':
libevent.cc:(.text+0x564): undefined reference to `evutil_make_socket_nonblocking'
libevent.cc:(.text+0x5da): undefined reference to `event_add'
/tmp/cctwJY4k.o: In function `run()':
libevent.cc:(.text+0x5f3): undefined reference to `event_base_new'
libevent.cc:(.text+0x63f): undefined reference to `evutil_make_socket_nonblocking'
libevent.cc:(.text+0x6d2): undefined reference to `event_new'
libevent.cc:(.text+0x6e7): undefined reference to `event_add'
libevent.cc:(.text+0x6f3): undefined reference to `event_base_dispatch'
collect2: error: ld returned 1 exit status
It seems like the compiler is finding the include files but not the object files.
I also tried configuring libevent without the --disable-shared option and then exported /home/tom/local/lib to the LD_LIBRARY_PATH but I still get the same error with the compile command:
g++ -I=/home/tom/local/include rot13server.cpp
Can anyone tell me what I am doing wrong?
Thanks
Can anyone tell me what I am doing wrong?
Just about everything.
The -I=/home/tom/local/include tells GCC to look in =/home/tom/local/include directory, which is unlikely to exist.
You want:
g++ -I/home/tom/local/include rot13server.cpp -c
g++ -L/home/tom/local/lib rot13server.o -levent -o rot13server

Problems compiling windows 64 program on linux - headers

I have been trying to compile a windows 64 program, MSVAR1.3, on linux and have had problems with Linux and the headers that the program calls. The program calls for:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#ifdef __BORLANDC__
#include <float.h>
If I run the compile (using gcc in linux) and try to use the -I flag to tell it where the headers are, it doesn't get any better than if I run the compilation without headers at all. I have included some of the output below (I get almost 300 lines of unrecognized variables).
I have also tried running it with an -lm flag for the math library and this reduces the unrecognized errors, but if there are flags relating to libraries for the other headers, I haven't been able to find them. PLEASE HELP!!!!
(Errors from running using the -I flag:)
gcc msvar1.3.c -o msvar1.3 -lm/tmp/ccpZIkC1.o: In function `main':
msvar1.3.c:(.text+0x38): undefined reference to `opengfsr'
msvar1.3.c:(.text+0x927): undefined reference to `gfsr8'
msvar1.3.c:(.text+0x94c): undefined reference to `gfsr8'
msvar1.3.c:(.text+0x971): undefined reference to `gfsr8'
msvar1.3.c:(.text+0x9a2): undefined reference to `disrand'
msvar1.3.c:(.text+0x111a): undefined reference to `printerr'
msvar1.3.c:(.text+0x1809): undefined reference to `printerr'
msvar1.3.c:(.text+0x1ad2): undefined reference to `printerr'
msvar1.3.c:(.text+0x1be6): undefined reference to `gfsr8'
msvar1.3.c:(.text+0x2773): undefined reference to `closegfsr'
msvar1.3.c:(.text+0x2791): undefined reference to `closegfsr'
/tmp/ccpZIkC1.o: In function `treesummary':
msvar1.3.c:(.text+0x2808): undefined reference to `printerr'
/tmp/ccpZIkC1.o: In function `read_params':
msvar1.3.c:(.text+0x2b1f): undefined reference to `printerr'
msvar1.3.c:(.text+0x2b64): undefined reference to `printerr'
msvar1.3.c:(.text+0x2b72): undefined reference to `intrand'
msvar1.3.c:(.text+0x2bb7): undefined reference to `printerr'
msvar1.3.c:(.text+0x3000): undefined reference to `printerr'
msvar1.3.c:(.text+0x3063): undefined reference to `printerr'
msvar1.3.c:(.text+0x3077): undefined reference to `printerr'
/tmp/ccpZIkC1.o: In function `choosepar':
msvar1.3.c:(.text+0x36fb): undefined reference to `gfsr8'
msvar1.3.c:(.text+0x374b): undefined reference to `gfsr4'
msvar1.3.c:(.text+0x3799): undefined reference to `gfsr4'
msvar1.3.c:(.text+0x37b8): undefined reference to `norm4'
msvar1.3.c:(.text+0x37e5): undefined reference to `gfsr4'
msvar1.3.c:(.text+0x3826): undefined reference to `norm4'
msvar1.3.c:(.text+0x3853): undefined reference to `gfsr4'
msvar1.3.c:(.text+0x3894): undefined reference to `norm4'
msvar1.3.c:(.text+0x38f7): undefined reference to `norm4'
"undefined reference" errors are not from missing headers - they're linker errors indicating you don't link with an object, nor have a -l (minus ell) flag specifying a library, that exports these symbols. The headers only constitute a promise that variables and out-of-lines function matching the header declarations will be found in an object/library you provide at link time - you're breaking that promise.
You need to either find the libraries containing those symbols, or find the source and compile them.
I compiled msvar1.3 with command:
gcc -o msvar1.3 myutil.c msvar1.3.c -lm

Unable to link to GraphicsMagik

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.

How can I verify linked libraries?

I am having lots of trouble getting a specific set of drivers working, called libnifalcon.
I am pretty sure that the installation was successful, but when I try to compile the example programs I get the errors:
mars#marslab:~/Documents/libnifalcon-1.0/examples/findfalcons$ g++ findfalcons.cpp
/tmp/cc8TtfGn.o: In function `runFalconTest()':
findfalcons.cpp:(.text+0x6b): undefined reference to `libnifalcon::FalconDevice::FalconDevice()'
findfalcons.cpp:(.text+0xdd): undefined reference to `libnifalcon::FalconDevice::getDeviceCount(unsigned int&)'
findfalcons.cpp:(.text+0x1bd): undefined reference to `libnifalcon::FalconDevice::open(unsigned int)'
findfalcons.cpp:(.text+0x224): undefined reference to `libnifalcon::FalconDevice::isFirmwareLoaded()'
findfalcons.cpp:(.text+0x2ac): undefined reference to `libnifalcon::FalconFirmware::loadFirmware(bool, unsigned int const&, unsigned char*)'
findfalcons.cpp:(.text+0x33b): undefined reference to `libnifalcon::FalconDevice::isFirmwareLoaded()'
findfalcons.cpp:(.text+0x3dd): undefined reference to `libnifalcon::FalconDevice::runIOLoop(unsigned int)'
findfalcons.cpp:(.text+0x504): undefined reference to `libnifalcon::FalconDevice::runIOLoop(unsigned int)'
findfalcons.cpp:(.text+0x512): undefined reference to `libnifalcon::FalconDevice::close()'
findfalcons.cpp:(.text+0x52b): undefined reference to `libnifalcon::FalconDevice::~FalconDevice()'
findfalcons.cpp:(.text+0x53f): undefined reference to `libnifalcon::FalconDevice::~FalconDevice()'
/tmp/cc8TtfGn.o: In function `void libnifalcon::FalconDevice::setFalconFirmware<libnifalcon::FalconFirmwareNovintSDK>()':
findfalcons.cpp:(.text._ZN11libnifalcon12FalconDevice17setFalconFirmwareINS_23FalconFirmwareNovintSDKEEEvv[void libnifalcon::FalconDevice::setFalconFirmware<libnifalcon::FalconFirmwareNovintSDK>()]+0x1d): undefined reference to `libnifalcon::FalconFirmwareNovintSDK::FalconFirmwareNovintSDK()'
collect2: ld returned 1 exit status
How can I verify the libraries are linked correctly? What can I do if they aren't?
You're not linking with anything, i.e.
g++ file.cpp
does not link to any libraries other than the standard library. You need to link with other modules or libraries, probably libnifalcon
g++ findfalcons.cpp -lnifalcon
or... you probably will need to do something like
g++ -L/path/to/libnifalcon findfalcons.cpp -lnifalcon
where -I tells where to look for libraries.