C++: matplotlibcpp.h and Python.h linker error - c++

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)

Related

upgrade libc from 2.21 to 2.28 gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf cross compiler

I am using gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf on my ubuntu system using NetBeans IDE. My cross compiler is having libc-2.21 where as some of the libraries requires libc-2.28.And my target machine(debian jessie) do have libc-2.28 .
How can I upgrade it?
This is the error message I am getting after compiling in Netbeans:
/opt/crosstool/arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/libavutil.so.56: undefined reference to 'fcntl64#GLIBC_2.28'
/opt/crosstool/arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/libsystemd.so.0: undefined reference to 'getrandom#GLIBC_2.25'
/opt/crosstool/arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/libbellesip.so.0: undefined reference to 'fcntl#GLIBC_2.28'
/opt/crosstool/arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/libavcodec.so.58: undefined reference to 'powf#GLIBC_2.27'
/opt/crosstool/arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/libsystemd.so.0: undefined reference to 'reallocarray#GLIBC_2.26'
/opt/crosstool/arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/libmediastreamer_voip.so.10: undefined reference to 'expf#GLIBC_2.27'
/opt/crosstool/arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/libpulsecommon-12.2.so: undefined reference to 'memfd_create#GLIBC_2.27'
/opt/crosstool/arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/libavcodec.so.58: undefined reference to 'exp2f#GLIBC_2.27'
/opt/crosstool/arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/libavcodec.so.58: undefined reference to 'log2f#GLIBC_2.27'
/opt/crosstool/arm-linux-gnueabihf/bin/../arm-linux-gnueabihf/libc/usr/lib/libortp.so.13: undefined reference to 'logf#GLIBC_2.27'
collect2: error: ld returned 1 exit status

linker error while building roborobo using SDL

I'm using robo robo simulator. It requires SDL to be installed. SDL was successfully installed using sudo apt-get install in Ubuntu
'make' was used to compile and link.
compilation was successful but while linking I got the following linker errors
[LD] roborobo
src/core/roborobo.o: In function `clean_up()':
roborobo.cpp:(.text+0x29): undefined reference to `SDL_FreeSurface'
roborobo.cpp:(.text+0x35): undefined reference to `SDL_FreeSurface'
roborobo.cpp:(.text+0x41): undefined reference to `SDL_FreeSurface'
roborobo.cpp:(.text+0x4d): undefined reference to `SDL_FreeSurface'
roborobo.cpp:(.text+0x59): undefined reference to `SDL_FreeSurface'
src/core/roborobo.o:roborobo.cpp:(.text+0x6a): more undefined references to `SDL_FreeSurface' follow
src/core/roborobo.o: In function `checkQuitEvent()':
roborobo.cpp:(.text+0xdff): undefined reference to `SDL_PollEvent'
src/core/roborobo.o: In function `handleKeyEvent(unsigned char*)':
roborobo.cpp:(.text+0xead): undefined reference to `SDL_Delay'
roborobo.cpp:(.text+0xf1a): undefined reference to `SDL_Delay'
roborobo.cpp:(.text+0xf43): undefined reference to `SDL_Delay'
roborobo.cpp:(.text+0x1037): undefined reference to `SDL_Delay'
roborobo.cpp:(.text+0x111e): undefined reference to `SDL_Delay'
src/core/roborobo.o:roborobo.cpp:(.text+0x1191): more undefined references to `SDL_Delay' follow
and many more
SDL_gfxPrimitives.c:(.text+0x7477): undefined reference to `SDL_UnlockSurface'
SDL_gfxPrimitives.c:(.text+0x7491): undefined reference to `SDL_UpperBlit'
SDL_gfxPrimitives.c:(.text+0x74e6): undefined reference to `SDL_CreateRGBSurface'
collect2: error: ld returned 1 exit status
make: [roborobo] Error 1 (ignored)
the make file also has sdl-config --cflags --libs -lSDL_image
the Makefile is in http://pastebin.com/5EdcZWAd
the entire console output after 'make' is in http://pastebin.com/yXDHR9xw

Undefine reference of <function name>

When I've try to compile program (test for my lib) I've got undefined reference of for every called method. I've read answers on "gcc undefined reference to", but it has not help.
PS I using: Debian 7.2.0 and C++11 standart.
#include <RFw/String.hpp>
#include <stdio.h>
using namespace RFw;
int main() {
Array<char> _arr_ (5);
_arr_[0] = 'b';
_arr_[1] = 'c';
printf("%c%c\n", _arr_[0], _arr_[2]);
printf(RFw::getVersion());
return 0;
}
Makefile target:
test:
c++ test.cpp -I./include-core/ -o bin/test -L./bin -l${core_NAME_ROOT}
Console output:
test.cpp:13:9: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
printf(RFw::getVersion());
^~~~~~~~~~~~~~~~~
1 warning generated.
/tmp/test-lxdZF4.o: In function `main':
test.cpp:(.text+0x20): undefined reference to `RFw::Array<char>::Array(int)'
test.cpp:(.text+0x33): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0x54): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0x75): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0x99): undefined reference to `RFw::Array<char>::operator[](int)'
test.cpp:(.text+0xff): undefined reference to `RFw::Array<char>::~Array()'
test.cpp:(.text+0x11a): undefined reference to `RFw::Array<char>::~Array()'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::operator[](int) const'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::Array(int)'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::getLength() const'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Exception::onThrow()'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::resize(int)'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::addElementOnEnd(char)'
./bin/libregemfw0.1-core.so: undefined reference to `vtable for RFw::Object'
./bin/libregemfw0.1-core.so: undefined reference to `typeinfo for RFw::Object'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Object::~Object()'
./bin/libregemfw0.1-core.so: undefined reference to `RFw::Array<char>::~Array()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test] Ошибка 1
The problem is that
c++ test.cpp -I./include-core/ -o bin/test -L./bin -l${core_NAME_ROOT}c++ test.cpp -I./include-core/ -o bin/test -L./bin -l${core_NAME_ROOT}
will first process the library and then your .cpp file. When processing a library, referenced symbols are resolved ("linked") and all unresolved symbols in the library that aren't needed are thrown away. That means that as soon as your .cpp file is being processed, these symbols are already rejected. You have the library twice in your command line, but the second one is being ignored since the library was already processed.
You should always put the libraries (once) at the end of the compiler command line:
c++ test.cpp -I./include-core/ -o bin/test test.cpp -L./bin -l${core_NAME_ROOT}

What libs should I include when compiling with mingw?

I'm trying to compile the MAPI example for windows, using MinGW compiler (on linux).
I tried straightforward approach:
$ i686-w64-mingw32-g++ swpmain.h swpmain.cpp swap.h swap.cpp
//
// bunch of warnings here...
//
/tmp/ccggw42y.o:swap.cpp:(.text+0x2f9): undefined reference to `_MAPIInitialize#4'
/tmp/ccggw42y.o:swap.cpp:(.text+0x31c): undefined reference to `_MAPIAllocateBuffer#8'
/tmp/ccggw42y.o:swap.cpp:(.text+0x350): undefined reference to `_MAPIUninitialize#0'
/tmp/ccggw42y.o:swap.cpp:(.text+0x41a): undefined reference to `_MAPIAllocateBuffer#8'
/tmp/ccggw42y.o:swap.cpp:(.text+0x445): undefined reference to `_MAPIAllocateBuffer#8'
/tmp/ccggw42y.o:swap.cpp:(.text+0x65f): undefined reference to `_MAPIAllocateBuffer#8'
/tmp/ccggw42y.o:swap.cpp:(.text+0xf5b): undefined reference to `_MAPIFreeBuffer#4'
/tmp/ccggw42y.o:swap.cpp:(.text+0xf6c): undefined reference to `_MAPIFreeBuffer#4'
/tmp/ccggw42y.o:swap.cpp:(.text+0x1782): undefined reference to `_MAPIFreeBuffer#4'
collect2: ld returned 1 exit status
ld error hints that I forgot to include some library - but I can't figure out which one. I tried searching files in usr/, but I only found mapi.h and mapix.h headers - no libraries.
What am I doing wrong here?

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.