How to build SOCI with PostgreSQL? - c++

I'm trying to build the SOCI library to run with PostgreSQL. I followed these steps:
Install PostgreSQL in Ubutu 15.10
Download SOCI source code
Extract SOCI code
I then run the following commands:
mkdir build
cd build
cmake -G "Unix Makefiles" -DWITH_BOOST=OFF -DWITH_POSTGRESQL=ON -DPOSTGRESQL_INCLUDE_DIR=/usr/local/pgsql/include -DPOSTGRESQL_LIBRARIES=/usr/local/pgsql/lib ../soci
At this point, CMake gave the following warnings:
WARNING: Target "soci_postgresql" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "soci_postgresql_static" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "soci_postgresql_test" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "soci_postgresql_test" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "soci_postgresql_test_static" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "soci_postgresql_test_static" requests linking to directory "/usr/local/pgsql/lib". Targets may link only to libraries. CMake is dropping the item.
Persisting with the build, I then ran make, which fails with the following error:
[ 98%] Building CXX object tests/postgresql/CMakeFiles/soci_postgresql_test.dir/test-postgresql.cpp.o
Linking CXX executable ../../bin/soci_postgresql_test
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQresultStatus'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQgetvalue'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQclear'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQserverVersion'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQresultErrorMessage'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQexec'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_lseek'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfsize'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQgetisnull'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQerrorMessage'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_open'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQexecPrepared'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQftype'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_close'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQexecParams'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfname'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQconnectdb'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQstatus'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQntuples'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQresultErrorField'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfformat'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_read'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQfinish'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQprepare'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `lo_write'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQcmdTuples'
../../lib/libsoci_postgresql.so.4.0.0: undefined reference to `PQnfields'
collect2: error: ld returned 1 exit status
tests/postgresql/CMakeFiles/soci_postgresql_test.dir/build.make:89: recipe for target 'bin/soci_postgresql_test' failed
make[2]: *** [bin/soci_postgresql_test] Error 1
CMakeFiles/Makefile2:609: recipe for target 'tests/postgresql/CMakeFiles/soci_postgresql_test.dir/all' failed
make[1]: *** [tests/postgresql/CMakeFiles/soci_postgresql_test.dir/all] Error 2
Makefile:126: recipe for target 'all' failed
make: *** [all] Error 2
Any idea what the cause of the CMake warnings and build error might be?

Try to call cmake with slightly different options
cmake -G "Unix Makefiles" -DWITH_BOOST=OFF -DWITH_POSTGRESQL=ON \
-DPOSTGRESQL_INCLUDE_DIR:STRING="/usr/local/pgsql/include" \
-DPOSTGRESQL_LIBRARIES:STRING="/usr/local/pgsql/lib" ../soci

I got the right answer from the github, here is link.
The following reply is largely taken from there, but repeated here for convenience (with cleanup and clarification):
-DPOSTGRESQL_LIBRARIES=/usr/local/psql/lib should point to the libraries, not directories.
This is what the following warning already highlights:
WARNING: Target "soci_postgresql" requests linking to directory
"/usr/local/postgresql/lib"
Try the following command instead (you may need to delete your CMakeCache.txt from the build directory first as well):
cmake -G "Unix Makefiles" -DWITH_BOOST=OFF -DWITH_POSTGRESQL=ON ../soci
On Linux systems where "postgresql-devel.x86_64 : PostgreSQL development header files and libraries" is installed, this command should be enough.

Related

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

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)

QT GStreamer Windows linker problems

I'm trying to compile and run the qml-sink example which is provided inside the gstreamer-good-plugin (QT Example). But currently I get a lot of undefined reference errors during the compile time. It seems that the linker does not link the libraries correctly.
I have checked the list of linked libraries and from my point of view all needed libs are listed.
E.g. gst_object_ref, gst_init, ... are undefined.
My setup:
Windows 10
Qt 5.11
Gstreamer 1.0
Gstremer devel 1.0
Gstreamer plugin good
Installed GStreamer version from here: GStreamer Download => gstreamer-1.0-devel-x86_64-1.14.3.msi and gstreamer-1.0-x86_64-1.14.3.msi
Can anyone please help me, how I can solve this problem?
Errortrace:
"C:\Program Files\CMake\bin\cmake.exe" --build . --target all
"C:\Program Files\CMake\bin\cmake.exe" -HC:\gst-plugins-good-1.14.4\tests\examples\qt\qmlsink -BC:\gst-plugins-good-1.14.4\tests\examples\qt\build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\gst-plugins-good-1.14.4\tests\examples\qt\build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe\CMakeFiles C:\gst-plugins-good-1.14.4\tests\examples\qt\build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe\CMakeFiles\progress.marks
D:/Qt/Tools/mingw530_32/bin/mingw32-make.exe -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory 'C:/gst-plugins-good-1.14.4/tests/examples/qt/build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe'
D:/Qt/Tools/mingw530_32/bin/mingw32-make.exe -f CMakeFiles\qml-example.dir\build.make CMakeFiles/qml-example.dir/depend
mingw32-make.exe[2]: Entering directory 'C:/gst-plugins-good-1.14.4/tests/examples/qt/build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles"
C:\gst-plugins-good-1.14.4\tests\examples\qt\qmlsink C:\gst-plugins-good-1.14.4\tests\examples\qt\qmlsink C:\gst-plugins-good-1.14.4\tests\examples\qt\build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe
C:\gst-plugins-good-1.14.4\tests\examples\qt\build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe C:\gst-plugins-good-1.14.4\tests\examples\qt\build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe\CMakeFiles\qml-example.dir\DependInfo.cmake --color=
mingw32-make.exe[2]: Leaving directory 'C:/gst-plugins-good-1.14.4/tests/examples/qt/build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe'
D:/Qt/Tools/mingw530_32/bin/mingw32-make.exe -f CMakeFiles\qml-example.dir\build.make CMakeFiles/qml-example.dir/build
mingw32-make.exe[2]: Entering directory 'C:/gst-plugins-good-1.14.4/tests/examples/qt/build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe'
[ 25%] Linking CXX executable qml-example.exe
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\qml-example.dir\link.txt --verbose=1
"C:\Program Files\CMake\bin\cmake.exe" -E remove -f CMakeFiles\qml-example.dir/objects.a
D:\Qt\Tools\mingw530_32\bin\ar.exe cr CMakeFiles\qml-example.dir/objects.a #CMakeFiles\qml-example.dir\objects1.rsp
D:\Qt\Tools\mingw530_32\bin\g++.exe -Wl,--whole-archive CMakeFiles\qml-example.dir/objects.a -Wl,--no-whole-archive -o qml-example.exe -Wl,--out-implib,libqml-example.dll.a -Wl,--major-image-version,0,--minor-image-version,0
#CMakeFiles\qml-example.dir\linklibs.rsp
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x2b): undefined reference to `gst_object_ref'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x87): undefined reference to `gst_object_unref'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0xa7): undefined reference to `operator delete(void*)'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0xc8): undefined reference to `operator delete(void*)'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0xf3): undefined reference to `gst_element_set_state'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x150): undefined reference to `gst_init'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x17d): undefined reference to `gst_pipeline_new'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x194): undefined reference to `gst_element_factory_make'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1ab): undefined reference to `gst_element_factory_make'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1c2): undefined reference to `gst_element_factory_make'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x203): undefined reference to `g_assertion_message_expr'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x208): undefined reference to `gst_bin_get_type'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x217): undefined reference to `g_type_check_instance_cast'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x23e): undefined reference to `gst_bin_add_many'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x25f): undefined reference to `gst_element_link_many'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x37f): undefined reference to `g_assertion_message_expr'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x3a1): undefined reference to `g_object_set'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x3ad): undefined reference to `operator new(unsigned int)'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x3f6): undefined reference to `gst_element_set_state'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x401): undefined reference to `gst_object_unref'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x41e): undefined reference to `gst_deinit'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x467): undefined reference to `operator delete(void*)'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text$_ZN5QListIP7QObjectE13detach_helperEi[__ZN5QListIP7QObjectE13detach_helperEi]+0x8c): undefined reference to `__cxa_begin_catch'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text$_ZN5QListIP7QObjectE13detach_helperEi[__ZN5QListIP7QObjectE13detach_helperEi]+0xa3): undefined reference to `__cxa_rethrow'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.text$_ZN5QListIP7QObjectE13detach_helperEi[__ZN5QListIP7QObjectE13detach_helperEi]+0xaa): undefined reference to `__cxa_end_catch'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.rdata$_ZTI10SetPlaying[__ZTI10SetPlaying]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.rdata$_ZTI9QRunnable[__ZTI9QRunnable]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.eh_frame$_ZN5QListIP7QObjectED1Ev+0x13): undefined reference to `__gxx_personality_v0'
CMakeFiles\qml-example.dir/objects.a(main.cpp.obj):main.cpp:(.eh_frame$_ZN5QListIP7QObjectE13detach_helperEi+0x13): undefined reference to `__gxx_personality_v0'
CMakeFiles\qml-example.dir/objects.a(qrc_qml.cpp.obj):qrc_qml.cpp:(.eh_frame+0x8b): undefined reference to `__gxx_personality_v0'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [qml-example.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles/qml-example.dir/all] Error 2
CMakeFiles\qml-example.dir\build.make:112: recipe for target 'qml-example.exe' failed
mingw32-make.exe[2]: Leaving directory 'C:/gst-plugins-good-1.14.4/tests/examples/qt/build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe'
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/qml-example.dir/all' failed
mingw32-make.exe[1]: Leaving directory 'C:/gst-plugins-good-1.14.4/tests/examples/qt/build-qmlsink-Desktop_Qt_5_11_1_MinGW_32bit-Vorgabe'
Makefile:82: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2
It looks like you're building for windows. The only way I've compiled the qml plugin on windows is using qmake using the provided .pro file. My experiments with compiling using the mingw toolchain provided by Qt were unsuccessful due to mismatching C++ ABI's between GStreamer and Qt. I ended up using MSVC/Visual Studio for compiling instead.
The undefined references to g_/gst_ probably means you don't have pkg-config setup correctly on your system. pkg-config.exe --modversion gstreamer-1.0 Should output the version of GStreamer you installed.
Where did you download GStreamer from? What GStreamer version exactly? Did you download binaries or did you compile it yourself?

MinGW/CMake Undefined Reference to ZLib

I have a project I want to build with CMake and compile with MinGW. The project uses Zlib. When I build with CMake I get no errors but then when I run MinGW Make it gives the following output:
C:\Projects\MultiMCBuild>C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe
.
.
.
[ 50%] Linking CXX shared library ..\libMultiMC_logic.dll
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x1f6c): undefined reference to 'z_inflateEnd'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x29e2): undefined reference to 'z_inflateInit2_'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x2a6d): undefined reference to 'z_get_crc_table'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x2ca7): undefined reference to 'z_inflateEnd'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x2f52): undefined reference to 'z_inflateInit2_'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x2f77): undefined reference to 'z_inflateEnd'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x3239): undefined reference to 'z_inflateInit2_'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x3317): undefined reference to 'z_inflateEnd'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x3626): undefined reference to 'z_crc32'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x371f): undefined reference to 'z_inflate'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x376a): undefined reference to 'z_crc32'
C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj):unzip.c:(.text+0x3a57): undefined reference to 'z_inflateEnd'
C:/Qt/Tools/mingw492_32/bin/../lib/gcc/i686-w64- mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe: C:/Projects/MultiMCBuild/External/Install/QuaZIP/lib/libquazip.a(unzip.c.obj): bad reloc address 0x20 in section `.eh_frame'
collect2.exe: error: ld returned 1 exit status
logic\CMakeFiles\MultiMC_logic.dir\build.make:3186: recipe for target 'libMultiMC_logic.dll' failed
mingw32-make[2]: * * * [libMultiMC_logic.dll] Error 1
CMakeFiles\Makefile2:1806: recipe for target 'logic/CMakeFiles/MultiMC_logic.dir/all' failed
mingw32-make[1]: * * * [logic/CMakeFiles/MultiMC_logic.dir/all] Error 2
makefile:159: recipe for target 'all' failed
mingw32-make: * * * [all] Error 2
Anyone have a clue what I can do to fix this? I read that the code can't find the ZLib library, how do I link it?
EDIT here is my CMakeLists.txt. I got this from the Git project.
I just tried to generate a small example to reproduce your errors. I took my test file from the home page of zlib http://zlib.net/zpipe.c
My initial CMakeLists.txt was
cmake_minimum_required(VERSION 3.4)
project(zlib_test)
set(ZLIB_TEST_SOURCES zpipe.c)
add_executable(${PROJECT_NAME} ${ZLIB_TEST_SOURCES})
And I got the same errors
[ 50%] Building C object CMakeFiles/zlib_test.dir/zpipe.c.o
[100%] Linking C executable zlib_test
CMakeFiles/zlib_test.dir/zpipe.c.o: In function `def':
zpipe.c:(.text+0x65): undefined reference to `deflateInit_'
zpipe.c:(.text+0xcd): undefined reference to `deflateEnd'
zpipe.c:(.text+0x135): undefined reference to `deflate'
zpipe.c:(.text+0x1cf): undefined reference to `deflateEnd'
zpipe.c:(.text+0x25d): undefined reference to `deflateEnd'
CMakeFiles/zlib_test.dir/zpipe.c.o: In function `inf':
zpipe.c:(.text+0x2eb): undefined reference to `inflateInit_'
zpipe.c:(.text+0x353): undefined reference to `inflateEnd'
zpipe.c:(.text+0x3a4): undefined reference to `inflate'
zpipe.c:(.text+0x404): undefined reference to `inflateEnd'
zpipe.c:(.text+0x476): undefined reference to `inflateEnd'
zpipe.c:(.text+0x4a6): undefined reference to `inflateEnd'
collect2: error: ld returned 1 exit status
make[2]: *** [zlib_test] Error 1
make[1]: *** [CMakeFiles/zlib_test.dir/all] Error 2
make: *** [all] Error 2
After changing CMakeLists.txt to this form
cmake_minimum_required(VERSION 3.4)
project(zlib_test)
find_package(ZLIB REQUIRED)
if (ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS})
endif()
set(ZLIB_TEST_SOURCES zpipe.c)
add_executable(${PROJECT_NAME} ${ZLIB_TEST_SOURCES})
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES})
I could compile the program.
So your problem is: Where is ZLIB added in your CMakeLists.txt? At least, you need the line find_package(ZLIB REQUIRED).

CMake linker not working correctly

I am trying to build my project using CMake but I am having error linking required libraries. I have this CMakeLists.txt in the root folder of my project:
cmake_minimum_required(VERSION 2.6)
project(test)
add_subdirectory(src)
And in my src folder, alongside my source files I have this CMakeLists.txt:
set (CMAKE_CXX_FLAGS "Wall -std=c++11" )
set (CMAKE_EXE_LINKER_FLAGS "-lSDL2 -lGL" )
file (GLOB SRCS *.cpp *.h )
add_executable(engine ${SRCS} )
I then go into the build folder and do cmake .. and it runs without any errors. When I do make, the compilation runs without any errors as well, but when it gets to the linking part, I get these errors:
CMakeFiles/test.dir/Application.cpp.o: In function `Application::onExecute()':
Application.cpp:(.text+0x41): undefined reference to `SDL_GetTicks'
Application.cpp:(.text+0x4e): undefined reference to `SDL_GetTicks'
Application.cpp:(.text+0xd7): undefined reference to `SDL_PollEvent'
CMakeFiles/test.dir/Application.cpp.o: In function `Application::render()':
Application.cpp:(.text+0x17b): undefined reference to `glClearColor'
Application.cpp:(.text+0x185): undefined reference to `glClear'
Application.cpp:(.text+0x194): undefined reference to `SDL_GL_SwapWindow'
CMakeFiles/test.dir/Application.cpp.o: In function `Application::cleanUp()':
Application.cpp:(.text+0x1b2): undefined reference to `SDL_GL_DeleteContext'
Application.cpp:(.text+0x1c1): undefined reference to `SDL_DestroyWindow'
Application.cpp:(.text+0x1c6): undefined reference to `SDL_Quit'
CMakeFiles/test.dir/Application.cpp.o: In function `Application::initialize()':
Application.cpp:(.text+0x1de): undefined reference to `SDL_Init'
Application.cpp:(.text+0x1ea): undefined reference to `SDL_GetError'
Application.cpp:(.text+0x22b): undefined reference to `SDL_CreateWindow'
Application.cpp:(.text+0x243): undefined reference to `SDL_GetError'
Application.cpp:(.text+0x25a): undefined reference to `SDL_Quit'
Application.cpp:(.text+0x270): undefined reference to `SDL_GL_SetAttribute'
Application.cpp:(.text+0x27f): undefined reference to `SDL_GL_SetAttribute'
Application.cpp:(.text+0x28e): undefined reference to `SDL_GL_SetAttribute'
Application.cpp:(.text+0x29d): undefined reference to `SDL_GL_CreateContext'
Application.cpp:(.text+0x2af): undefined reference to `glGetString'
collect2: error: ld returned 1 exit status
make[2]: *** [src/test] Error 1
make[1]: *** [src/CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
I have the correct includes in my header files and I was able to compile and run using only make so I think the linker flags I tell CMake aren't being passed to the compiler. How can I fix this?
You have to use the cmake command target_link_libraries to reference SDL libs.

Linking to boost libraries when building pcl-1.7.1 from source

I have downloaded the pcl-1.7.1 release from github and have tried to build the code using
cd PCL-1.6.0 && mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
sudo make install
The cmake command runs successful and and writes this concerning boost
-- Boost version: 1.55.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- thread
-- date_time
-- iostreams
The problem comes with the make command which after some time returns the following error:
Scanning dependencies of target pcl_convert_pcd_ascii_binary
[ 12%] Building CXX object io/tools/CMakeFiles/pcl_convert_pcd_ascii_binary.dir/convert_pcd_ascii_binary.cpp.o
Linking CXX executable ../../bin/pcl_convert_pcd_ascii_binary
../../lib/libpcl_common.so.1.7.1: error: undefined reference to 'boost::thread::join_noexcept()'
../../lib/libpcl_common.so.1.7.1: error: undefined reference to 'boost::thread::start_thread_noexcept()'
../../lib/libpcl_io.so.1.7.1: error: undefined reference to 'boost::filesystem::detail::permissions(boost::filesystem::path const&, boost::filesystem::perms, boost::system::error_code*)'
../../lib/libpcl_io.so.1.7.1: error: undefined reference to 'boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
../../lib/libpcl_io.so.1.7.1: error: undefined reference to 'boost::filesystem::path::extension() const'
../../lib/libpcl_io.so.1.7.1: error: undefined reference to 'boost::filesystem::detail::dir_itr_close(void*&, void*&)'
../../lib/libpcl_io.so.1.7.1: error: undefined reference to 'boost::filesystem::path::stem() const'
../../lib/libpcl_io.so.1.7.1: error: undefined reference to 'boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
../../lib/libpcl_io.so.1.7.1: error: undefined reference to 'boost::filesystem::detail::directory_iterator_increment(boost::filesystem::directory_iterator&, boost::system::error_code*)'
../../lib/libpcl_io.so.1.7.1: error: undefined reference to 'boost::filesystem::directory_entry::m_get_status(boost::system::error_code*) const'
../../lib/libpcl_io.so.1.7.1: error: undefined reference to 'boost::thread::do_try_join_until_noexcept(timespec const&, bool&)'
collect2: ld returned 1 exit status
make[2]: *** [bin/pcl_convert_pcd_ascii_binary] Error 1
make[1]: *** [io/tools/CMakeFiles/pcl_convert_pcd_ascii_binary.dir/all] Error 2
make: *** [all] Error 2
Is it correct that this is a linking problem? can it be the boost installation that causes the problem?
I have built the boost library from source (version 1.55.0) by executing the following inside the boost_1_55_0 directory
sudo ./bootstrap
sudo ./b2 install
The boost is then installed in /usr/local/include and /usr/local/lib
I use 32 bit Ubuntu 12.04
I found some libboost files in /usr/lib which I forgot to delete from the last install of boost (as pointed out by #D.J.Duff). Removing those files and intstalling boost again fixed the problem.