Google test not working - linker

I'm on Arch Linux, cloned the gtest repo, cmake-ed google test and installed. The result are as follows:
- Install configuration: ""
-- Up-to-date: /usr/local/lib/libgmock.a
-- Up-to-date: /usr/local/lib/libgmock_main.a
-- Up-to-date: /usr/local/include/gmock
-- Up-to-date: /usr/local/include/gmock/gmock-matchers.h
-- Up-to-date: /usr/local/include/gmock/gmock-generated-actions.h.pump
-- Up-to-date: /usr/local/include/gmock/gmock-spec-builders.h
-- Up-to-date: /usr/local/include/gmock/gmock-cardinalities.h
-- Up-to-date: /usr/local/include/gmock/gmock-more-actions.h
-- Up-to-date: /usr/local/include/gmock/gmock-generated-actions.h
-- Up-to-date: /usr/local/include/gmock/gmock-more-matchers.h
-- Up-to-date: /usr/local/include/gmock/gmock-actions.h
-- Up-to-date: /usr/local/include/gmock/gmock-generated-matchers.h
-- Up-to-date: /usr/local/include/gmock/gmock-generated-function-mockers.h.pump
-- Up-to-date: /usr/local/include/gmock/gmock-generated-matchers.h.pump
-- Up-to-date: /usr/local/include/gmock/gmock-generated-nice-strict.h.pump
-- Up-to-date: /usr/local/include/gmock/gmock-generated-nice-strict.h
-- Up-to-date: /usr/local/include/gmock/gmock-generated-function-mockers.h
-- Up-to-date: /usr/local/include/gmock/internal
-- Up-to-date: /usr/local/include/gmock/internal/gmock-generated-internal-utils.h.pump
-- Up-to-date: /usr/local/include/gmock/internal/custom
-- Up-to-date: /usr/local/include/gmock/internal/custom/gmock-matchers.h
-- Up-to-date: /usr/local/include/gmock/internal/custom/gmock-generated-actions.h.pump
-- Up-to-date: /usr/local/include/gmock/internal/custom/gmock-generated-actions.h
-- Up-to-date: /usr/local/include/gmock/internal/custom/gmock-port.h
-- Up-to-date: /usr/local/include/gmock/internal/gmock-generated-internal-utils.h
-- Up-to-date: /usr/local/include/gmock/internal/gmock-port.h
-- Up-to-date: /usr/local/include/gmock/internal/gmock-internal-utils.h
-- Up-to-date: /usr/local/include/gmock/gmock.h
-- Up-to-date: /usr/local/lib/libgtest.a
-- Up-to-date: /usr/local/lib/libgtest_main.a
-- Up-to-date: /usr/local/include/gtest
-- Up-to-date: /usr/local/include/gtest/gtest_prod.h
-- Up-to-date: /usr/local/include/gtest/gtest-param-test.h
-- Up-to-date: /usr/local/include/gtest/gtest-param-test.h.pump
-- Up-to-date: /usr/local/include/gtest/gtest-spi.h
-- Up-to-date: /usr/local/include/gtest/gtest-test-part.h
-- Up-to-date: /usr/local/include/gtest/gtest-typed-test.h
-- Up-to-date: /usr/local/include/gtest/gtest-message.h
-- Up-to-date: /usr/local/include/gtest/gtest-death-test.h
-- Up-to-date: /usr/local/include/gtest/gtest_pred_impl.h
-- Up-to-date: /usr/local/include/gtest/internal
-- Up-to-date: /usr/local/include/gtest/internal/gtest-internal.h
-- Up-to-date: /usr/local/include/gtest/internal/gtest-param-util-generated.h
-- Up-to-date: /usr/local/include/gtest/internal/gtest-param-util-generated.h.pump
-- Up-to-date: /usr/local/include/gtest/internal/custom
-- Up-to-date: /usr/local/include/gtest/internal/custom/gtest.h
-- Up-to-date: /usr/local/include/gtest/internal/custom/gtest-printers.h
-- Up-to-date: /usr/local/include/gtest/internal/custom/gtest-port.h
-- Up-to-date: /usr/local/include/gtest/internal/gtest-type-util.h.pump
-- Up-to-date: /usr/local/include/gtest/internal/gtest-string.h
-- Up-to-date: /usr/local/include/gtest/internal/gtest-type-util.h
-- Up-to-date: /usr/local/include/gtest/internal/gtest-linked_ptr.h
-- Up-to-date: /usr/local/include/gtest/internal/gtest-port-arch.h
-- Up-to-date: /usr/local/include/gtest/internal/gtest-death-test-internal.h
-- Up-to-date: /usr/local/include/gtest/internal/gtest-tuple.h
-- Up-to-date: /usr/local/include/gtest/internal/gtest-filepath.h
-- Up-to-date: /usr/local/include/gtest/internal/gtest-tuple.h.pump
-- Up-to-date: /usr/local/include/gtest/internal/gtest-param-util.h
-- Up-to-date: /usr/local/include/gtest/internal/gtest-port.h
-- Up-to-date: /usr/local/include/gtest/gtest.h
-- Up-to-date: /usr/local/include/gtest/gtest-printers.h
Checking linkage gives me:
[user#machine]$ sudo ldconfig -v | grep gtest
ldconfig: Path `/usr/lib64' given more than once
ldconfig: Can't stat /usr/libx32: No such file or directory
libgtest1.so -> libgtest1.so
Result: undefined reference to testing::* for all the calls to the googletest library. It doesn't link. (i.e.: on all ASSERT_* etc..)
here's a sample:
CMakeFiles/mylib.dir/tests/main.cpp.o: In function `main':
/home/user/git_repos/projects/mylib/tests/main.cpp:33: multiple definition of `main'
CMakeFiles/mylib.dir/tests/src/main.cpp.o:/home/user/git_repos/projects/mylib/tests/src/main.cpp:4: first defined here
CMakeFiles/mylib.dir/tests/src/main.cpp.o: In function `A_B_Test::TestBody()':
/home/user/git_repos/projects/mylib/tests/src/main.cpp:3: undefined reference to `testing::Message::Message()'
/home/user/git_repos/projects/mylib/tests/src/main.cpp:3: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/home/user/git_repos/projects/mylib/tests/src/main.cpp:3: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/home/user/git_repos/projects/mylib/tests/src/main.cpp:3: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/home/user/git_repos/projects/mylib/tests/src/main.cpp:3: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
CMakeFiles/mylib.dir/tests/src/main.cpp.o: In function `main':
/home/user/git_repos/projects/mylib/tests/src/main.cpp:5: undefined reference to `testing::InitGoogleTest(int*, char**)'
etc...
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.4)
project(mylib)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCE_FILES
src/lib1.h
)
set(TEST_FILES
tests/lib1.h
tests/main.cpp
)
enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(mylib ${TEST_FILES} ${SOURCE_FILES})
Any help to get this thing working after having spent 3 full days of grind would be appreciated!
(btw, I'm using Clion)

You have told CMake where to look for gtest header files, but not to link against the library. Since it is installed in a standard path /usr/local/lib it'll probably be enough to include a line like this in your CMakeLists.txt after the add_executable command:
target_link_libraries(mylib gtest)
or
target_link_libraries(mylib gtest_main gtest)
if you are not providing your own custom main function.
Note: mylib is a kind of misleading name for your test executable.

You are not linking against libgtest.
A good example how to use cmake and goggle test can be found here: https://gist.github.com/oneamtu/3734295

Related

building Gstreamer mpegts project with Cmake

We are trying to use Gstreamer's mpegts pluging to record a video stream stream using the following Gstreamer example code https://gstreamer.freedesktop.org/documentation/mpegtsmux/mpegtsmux.html?gi-language=c. When we compile the code using gcc mpegtstest.c -o mpegtstest `pkg-config --cflags --libs gstreamer-1.0 gstreamer-mpegts-1.0` -v everything works as expected and the program records with no issues. We are now trying to compile the code using cmake and make. cmake generates correctly but make fails with error.
/usr/bin/ld: cannot find -lgstreamer-mpegts-1.0.
CMakeLists.txt
##################### STANDARD HEADER #########################
cmake_minimum_required(VERSION 2.6)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "" FORCE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeHelpers/")
##################### PROJECT DEF #############################
project(mpegsttest)
################### VARIABLES #################################
include_directories("${PROJECT_BINARY_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/../")
set(MPEGTS_TEST_SOURCES
mpegtstest.c
)
####################### Targets ########################
add_executable(${CMAKE_PROJECT_NAME} ${MPEGTS_TEST_SOURCES})
################### Linked Libraries ###################
find_package(GLIB2 REQUIRED)
include_directories(${GLIB2_INCLUDE_DIRS})
include_directories("/usr/include/gio-unix-2.0")
target_link_libraries(${CMAKE_PROJECT_NAME} ${GLIB2_LIBRARIES} gobject-2.0 gio-2.0)
find_package(GStreamer REQUIRED)
include_directories(${GSTREAMER_INCLUDE_DIRS})
target_link_libraries(${CMAKE_PROJECT_NAME} ${GSTREAMER_LIBRARIES})
include_directories(${GSTREAMER-MPEGTS_INCLUDE_DIRS})
target_link_libraries(${CMAKE_PROJECT_NAME} gstreamer-mpegts-1.0)
cmake output
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for one of the modules 'glib-2.0'
-- Found GLib2: glib-2.0 /usr/include/glib-2.0;/usr/lib/glib-2.0/include
-- Looking for include file glib/gregex.h
-- Looking for include file glib/gregex.h - not found
-- Looking for include file glib/gchecksum.h
-- Looking for include file glib/gchecksum.h - not found
-- Checking for module 'gstreamer-1.0 >= '
-- Found gstreamer-1.0 , version 1.6.3
-- Checking for module 'gstreamer-base-1.0 >= '
-- Found gstreamer-base-1.0 , version 1.6.3
-- Checking for module 'gstreamer-app-1.0 >= '
-- Found gstreamer-app-1.0 , version 1.6.3
-- Checking for module 'gstreamer-audio-1.0 >= '
-- Found gstreamer-audio-1.0 , version 1.6.3
-- Checking for module 'gstreamer-fft-1.0 >= '
-- Found gstreamer-fft-1.0 , version 1.6.3
-- Checking for module 'gstreamer-mpegts-1.0>=1.4.0'
-- Found gstreamer-mpegts-1.0, version 1.6.3
-- Checking for module 'gstreamer-pbutils-1.0 >= '
-- Found gstreamer-pbutils-1.0 , version 1.6.3
-- Checking for module 'gstreamer-tag-1.0 >= '
-- Found gstreamer-tag-1.0 , version 1.6.3
-- Checking for module 'gstreamer-video-1.0 >= '
-- Found gstreamer-video-1.0 , version 1.6.3
-- Found GStreamer: GSTREAMER_INCLUDE_DIRS;GSTREAMER_LIBRARIES;GSTREAMER_VERSION;GSTREAMER_BASE_INCLUDE_DIRS;GSTREAMER_BASE_LIBRARIES
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dev3lx/build/mpegts
make --trace output
Makefile:176: target 'cmake_check_build_system' does not exist
/usr/bin/cmake -H/home/dev3lx/Development/mptestsrc -B/home/dev3lx/build/mpegts --check-build-system CMakeFiles/Makefile.cmake 0
Makefile:83: update target 'all' due to: cmake_check_build_system
/usr/bin/cmake -E cmake_progress_start /home/dev3lx/build/mpegts/CMakeFiles /home/dev3lx/build/mpegts/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
CMakeFiles/Makefile2:67: target 'CMakeFiles/mpegsttest.dir/all' does not exist
make -f CMakeFiles/mpegsttest.dir/build.make CMakeFiles/mpegsttest.dir/depend
CMakeFiles/mpegsttest.dir/build.make:112: target 'CMakeFiles/mpegsttest.dir/depend' does not exist
cd /home/dev3lx/build/mpegts && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/dev3lx/Development/mptestsrc /home/dev3lx/Development/mptestsrc /home/dev3lx/build/mpegts /home/dev3lx/build/mpegts /home/dev3lx/build/mpegts/CMakeFiles/mpegsttest.dir/DependInfo.cmake --color=
Scanning dependencies of target mpegsttest
make -f CMakeFiles/mpegsttest.dir/build.make CMakeFiles/mpegsttest.dir/build
CMakeFiles/mpegsttest.dir/build.make:62: update target 'CMakeFiles/mpegsttest.dir/mpegtstest.c.o' due to: /home/dev3lx/Development/mptestsrc/mpegtstest.c /usr/include/glib-2.0/glib-object.h /usr/include/glib-2.0/glib.h /usr/include/glib-2.0/glib/deprecated/gallocator.h /usr/include/glib-2.0/glib/deprecated/gcache.h /usr/include/glib-2.0/glib/deprecated/gcompletion.h /usr/include/glib-2.0/glib/deprecated/gmain.h /usr/include/glib-2.0/glib/deprecated/grel.h /usr/include/glib-2.0/glib/deprecated/gthread.h /usr/include/glib-2.0/glib/galloca.h /usr/include/glib-2.0/glib/garray.h /usr/include/glib-2.0/glib/gasyncqueue.h /usr/include/glib-2.0/glib/gatomic.h /usr/include/glib-2.0/glib/gbacktrace.h /usr/include/glib-2.0/glib/gbase64.h /usr/include/glib-2.0/glib/gbitlock.h /usr/include/glib-2.0/glib/gbookmarkfile.h /usr/include/glib-2.0/glib/gbytes.h /usr/include/glib-2.0/glib/gcharset.h /usr/include/glib-2.0/glib/gchecksum.h /usr/include/glib-2.0/glib/gconvert.h /usr/include/glib-2.0/glib/gdataset.h /usr/include/glib-2.0/glib/gdate.h /usr/include/glib-2.0/glib/gdatetime.h /usr/include/glib-2.0/glib/gdir.h /usr/include/glib-2.0/glib/genviron.h /usr/include/glib-2.0/glib/gerror.h /usr/include/glib-2.0/glib/gfileutils.h /usr/include/glib-2.0/glib/ggettext.h /usr/include/glib-2.0/glib/ghash.h /usr/include/glib-2.0/glib/ghmac.h /usr/include/glib-2.0/glib/ghook.h /usr/include/glib-2.0/glib/ghostutils.h /usr/include/glib-2.0/glib/giochannel.h /usr/include/glib-2.0/glib/gkeyfile.h /usr/include/glib-2.0/glib/glib-autocleanups.h /usr/include/glib-2.0/glib/glist.h /usr/include/glib-2.0/glib/gmacros.h /usr/include/glib-2.0/glib/gmain.h /usr/include/glib-2.0/glib/gmappedfile.h /usr/include/glib-2.0/glib/gmarkup.h /usr/include/glib-2.0/glib/gmem.h /usr/include/glib-2.0/glib/gmessages.h /usr/include/glib-2.0/glib/gnode.h /usr/include/glib-2.0/glib/goption.h /usr/include/glib-2.0/glib/gpattern.h /usr/include/glib-2.0/glib/gpoll.h /usr/include/glib-2.0/glib/gprimes.h /usr/include/glib-2.0/glib/gqsort.h /usr/include/glib-2.0/glib/gquark.h /usr/include/glib-2.0/glib/gqueue.h /usr/include/glib-2.0/glib/grand.h /usr/include/glib-2.0/glib/gregex.h /usr/include/glib-2.0/glib/gscanner.h /usr/include/glib-2.0/glib/gsequence.h /usr/include/glib-2.0/glib/gshell.h /usr/include/glib-2.0/glib/gslice.h /usr/include/glib-2.0/glib/gslist.h /usr/include/glib-2.0/glib/gspawn.h /usr/include/glib-2.0/glib/gstrfuncs.h /usr/include/glib-2.0/glib/gstring.h /usr/include/glib-2.0/glib/gstringchunk.h /usr/include/glib-2.0/glib/gtestutils.h /usr/include/glib-2.0/glib/gthread.h /usr/include/glib-2.0/glib/gthreadpool.h /usr/include/glib-2.0/glib/gtimer.h /usr/include/glib-2.0/glib/gtimezone.h /usr/include/glib-2.0/glib/gtrashstack.h /usr/include/glib-2.0/glib/gtree.h /usr/include/glib-2.0/glib/gtypes.h /usr/include/glib-2.0/glib/gunicode.h /usr/include/glib-2.0/glib/gurifuncs.h /usr/include/glib-2.0/glib/gutils.h /usr/include/glib-2.0/glib/gvariant.h /usr/include/glib-2.0/glib/gvarianttype.h /usr/include/glib-2.0/glib/gversion.h /usr/include/glib-2.0/glib/gversionmacros.h /usr/include/glib-2.0/glib/gwin32.h /usr/include/glib-2.0/gobject/gbinding.h /usr/include/glib-2.0/gobject/gboxed.h /usr/include/glib-2.0/gobject/gclosure.h /usr/include/glib-2.0/gobject/genums.h /usr/include/glib-2.0/gobject/glib-types.h /usr/include/glib-2.0/gobject/gmarshal.h /usr/include/glib-2.0/gobject/gobject-autocleanups.h /usr/include/glib-2.0/gobject/gobject.h /usr/include/glib-2.0/gobject/gparam.h /usr/include/glib-2.0/gobject/gparamspecs.h /usr/include/glib-2.0/gobject/gsignal.h /usr/include/glib-2.0/gobject/gsourceclosure.h /usr/include/glib-2.0/gobject/gtype.h /usr/include/glib-2.0/gobject/gtypemodule.h /usr/include/glib-2.0/gobject/gtypeplugin.h /usr/include/glib-2.0/gobject/gvalue.h /usr/include/glib-2.0/gobject/gvaluearray.h /usr/include/glib-2.0/gobject/gvaluetypes.h /usr/include/gstreamer-1.0/gst/glib-compat.h /usr/include/gstreamer-1.0/gst/gst.h /usr/include/gstreamer-1.0/gst/gstallocator.h /usr/include/gstreamer-1.0/gst/gstatomicqueue.h /usr/include/gstreamer-1.0/gst/gstbin.h /usr/include/gstreamer-1.0/gst/gstbuffer.h /usr/include/gstreamer-1.0/gst/gstbufferlist.h /usr/include/gstreamer-1.0/gst/gstbufferpool.h /usr/include/gstreamer-1.0/gst/gstbus.h /usr/include/gstreamer-1.0/gst/gstcaps.h /usr/include/gstreamer-1.0/gst/gstcapsfeatures.h /usr/include/gstreamer-1.0/gst/gstchildproxy.h /usr/include/gstreamer-1.0/gst/gstclock.h /usr/include/gstreamer-1.0/gst/gstcompat.h /usr/include/gstreamer-1.0/gst/gstcontext.h /usr/include/gstreamer-1.0/gst/gstcontrolbinding.h /usr/include/gstreamer-1.0/gst/gstcontrolsource.h /usr/include/gstreamer-1.0/gst/gstdatetime.h /usr/include/gstreamer-1.0/gst/gstdebugutils.h /usr/include/gstreamer-1.0/gst/gstdevice.h /usr/include/gstreamer-1.0/gst/gstdevicemonitor.h /usr/include/gstreamer-1.0/gst/gstdeviceprovider.h /usr/include/gstreamer-1.0/gst/gstdeviceproviderfactory.h /usr/include/gstreamer-1.0/gst/gstelement.h /usr/include/gstreamer-1.0/gst/gstelementfactory.h /usr/include/gstreamer-1.0/gst/gstelementmetadata.h /usr/include/gstreamer-1.0/gst/gstenumtypes.h /usr/include/gstreamer-1.0/gst/gsterror.h /usr/include/gstreamer-1.0/gst/gstevent.h /usr/include/gstreamer-1.0/gst/gstformat.h /usr/include/gstreamer-1.0/gst/gstghostpad.h /usr/include/gstreamer-1.0/gst/gstinfo.h /usr/include/gstreamer-1.0/gst/gstiterator.h /usr/include/gstreamer-1.0/gst/gstmacros.h /usr/include/gstreamer-1.0/gst/gstmemory.h /usr/include/gstreamer-1.0/gst/gstmessage.h /usr/include/gstreamer-1.0/gst/gstmeta.h /usr/include/gstreamer-1.0/gst/gstminiobject.h /usr/include/gstreamer-1.0/gst/gstobject.h /usr/include/gstreamer-1.0/gst/gstpad.h /usr/include/gstreamer-1.0/gst/gstpadtemplate.h /usr/include/gstreamer-1.0/gst/gstparamspecs.h /usr/include/gstreamer-1.0/gst/gstparse.h /usr/include/gstreamer-1.0/gst/gstpipeline.h /usr/include/gstreamer-1.0/gst/gstplugin.h /usr/include/gstreamer-1.0/gst/gstpluginfeature.h /usr/include/gstreamer-1.0/gst/gstpoll.h /usr/include/gstreamer-1.0/gst/gstpreset.h /usr/include/gstreamer-1.0/gst/gstprotection.h /usr/include/gstreamer-1.0/gst/gstquery.h /usr/include/gstreamer-1.0/gst/gstregistry.h /usr/include/gstreamer-1.0/gst/gstsample.h /usr/include/gstreamer-1.0/gst/gstsegment.h /usr/include/gstreamer-1.0/gst/gststructure.h /usr/include/gstreamer-1.0/gst/gstsystemclock.h /usr/include/gstreamer-1.0/gst/gsttaglist.h /usr/include/gstreamer-1.0/gst/gsttagsetter.h /usr/include/gstreamer-1.0/gst/gsttask.h /usr/include/gstreamer-1.0/gst/gsttaskpool.h /usr/include/gstreamer-1.0/gst/gsttoc.h /usr/include/gstreamer-1.0/gst/gsttocsetter.h /usr/include/gstreamer-1.0/gst/gsttypefind.h /usr/include/gstreamer-1.0/gst/gsttypefindfactory.h /usr/include/gstreamer-1.0/gst/gsturi.h /usr/include/gstreamer-1.0/gst/gstutils.h /usr/include/gstreamer-1.0/gst/gstvalue.h /usr/include/gstreamer-1.0/gst/gstversion.h /usr/include/gstreamer-1.0/gst/mpegts/gst-atsc-section.h /usr/include/gstreamer-1.0/gst/mpegts/gst-dvb-descriptor.h /usr/include/gstreamer-1.0/gst/mpegts/gst-dvb-section.h /usr/include/gstreamer-1.0/gst/mpegts/gst-scte-section.h /usr/include/gstreamer-1.0/gst/mpegts/gstmpegts-enumtypes.h /usr/include/gstreamer-1.0/gst/mpegts/gstmpegtsdescriptor.h /usr/include/gstreamer-1.0/gst/mpegts/gstmpegtssection.h /usr/include/gstreamer-1.0/gst/mpegts/mpegts.h /usr/lib/glib-2.0/include/glibconfig.h /usr/lib/gstreamer-1.0/include/gst/gstconfig.h CMakeFiles/mpegsttest.dir/flags.make
/usr/bin/cmake -E cmake_echo_color --switch= --green --progress-dir=/home/dev3lx/build/mpegts/CMakeFiles --progress-num=1 "Building C object CMakeFiles/mpegsttest.dir/mpegtstest.c.o"
[ 50%] Building C object CMakeFiles/mpegsttest.dir/mpegtstest.c.o
/usr/bin/cc -I/home/dev3lx/build/mpegts -I/home/dev3lx/Development/mptestsrc/.. -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/gio-unix-2.0 -I/usr/include/gstreamer-1.0 -I/usr/lib/gstreamer-1.0/include -o CMakeFiles/mpegsttest.dir/mpegtstest.c.o -c /home/dev3lx/Development/mptestsrc/mpegtstest.c
CMakeFiles/mpegsttest.dir/build.make:95: update target 'mpegsttest' due to: CMakeFiles/mpegsttest.dir/link.txt CMakeFiles/mpegsttest.dir/mpegtstest.c.o CMakeFiles/mpegsttest.dir/build.make /usr/lib64/libgstreamer-1.0.so
/usr/bin/cmake -E cmake_echo_color --switch= --green --bold --progress-dir=/home/dev3lx/build/mpegts/CMakeFiles --progress-num=2 "Linking C executable mpegsttest"
[100%] Linking C executable mpegsttest
/usr/bin/cmake -E cmake_link_script CMakeFiles/mpegsttest.dir/link.txt --verbose=
/usr/bin/ld: cannot find -lgstreamer-mpegts-1.0
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/mpegsttest.dir/build.make:96: mpegsttest] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/mpegsttest.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
After searching online and trying a few different things found online like here and looking at Github code we don't know why or how to fix it. Any advice or assistance is much appreciated. thanks in advance.
Solution
Thanks to nega's comment and solution, changing include_directories(${GSTREAMER-MPEGTS_INCLUDE_DIRS}) to include_directories(${GSTREAMER_MPEGTS_INCLUDE_DIRS}) worked.
Based on your cmake output, I'd guess that you're using a version of FindGStreamer.cmake cribbed from WebKit. If that's the case, the variable you want to use is GSTREAMER_MPEGTS_INCLUDE_DIRS. Note the lack of a hyphen in the variable name.
If that's not the case, use a simple message() statement before the use of a variable to show you its value during the cmake step.
In your CMakeLists.txt:
message("GMID: ${GSTREAMER_MPEGTS_INCLUDE_DIRS}")
include_directories(${GSTREAMER_MPEGTS_INCLUDE_DIRS})
target_link_libraries(${CMAKE_PROJECT_NAME} gstreamer-mpegts-1.0)
In your shell:
$ cmake ../src |grep -i ^gmid
GMID: /usr/local/Cellar/libffi/3.3_2/include;/usr/local/Cellar/gst-plugins-bad/1.18.3/include/gstreamer-1.0;/usr/local/Cellar/gstreamer/1.18.3/include/gstreamer-1.0;/usr/local/Cellar/glib/2.66.7/include;/usr/local/Cellar/glib/2.66.7/include/glib-2.0;/usr/local/Cellar/glib/2.66.7/lib/glib-2.0/include;/usr/local/opt/gettext/include;/usr/local/Cellar/pcre/8.44/include
Another easy debugging step is to grep the cache after running cmake.
$ grep -i ^gstream CMakeCache.txt
GSTREAMER_APP_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstapp-1.0.dylib
GSTREAMER_AUDIO_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstaudio-1.0.dylib
GSTREAMER_BASE_LIBRARIES:FILEPATH=/usr/local/Cellar/gstreamer/1.18.3/lib/libgstbase-1.0.dylib
GSTREAMER_CODECPARSERS_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-bad/1.18.3/lib/libgstcodecparsers-1.0.dylib
GSTREAMER_FFT_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstfft-1.0.dylib
GSTREAMER_FULL_LIBRARIES:FILEPATH=GSTREAMER_FULL_LIBRARIES-NOTFOUND
GSTREAMER_GL_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstgl-1.0.dylib
GSTREAMER_LIBRARIES:FILEPATH=/usr/local/Cellar/gstreamer/1.18.3/lib/libgstreamer-1.0.dylib
GSTREAMER_MPEGTS_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-bad/1.18.3/lib/libgstmpegts-1.0.dylib
GSTREAMER_PBUTILS_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstpbutils-1.0.dylib
GSTREAMER_TAG_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgsttag-1.0.dylib
GSTREAMER_VIDEO_LIBRARIES:FILEPATH=/usr/local/Cellar/gst-plugins-base/1.18.3/lib/libgstvideo-1.0.dylib

CMAKE dont find the libmpdclient-2.13 library

I´m new to cmake and i need help to build the ympd https://github.com/notandy/ympd project on windows
1. Install libmpdclient
I installed the libmpdclient-2.13 library from https://www.musicpd.org/libs/libmpdclient/
i did the steps to build the libmpdclient from the github repo
https://github.com/MusicPlayerDaemon/libmpdclient
This works well and got the following output with the .dll file:
2. Build the ympd project
I created a folder /build and inside this folder i did
cmake ..
i got this errors:
C:\mpd\ympd\build>cmake ..
-- Building for: Visual Studio 15 2017
-- Selecting Windows SDK version 10.0.15063.0 to target Windows 10.0.16299.
-- The C compiler identification is MSVC 19.11.25508.2
-- The CXX compiler identification is MSVC 19.11.25508.2
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.11.25503/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: C:/MinGW/bin/pkg-config.exe (found version "0.26")
CMake Error at G:/Programme/CMake/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find LibMPDClient (missing: LIBMPDCLIENT_LIBRARY
LIBMPDCLIENT_INCLUDE_DIR)
Call Stack (most recent call first):
G:/Programme/CMake/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
cmake/FindLibMPDClient.cmake:27 (find_package_handle_standard_args)
CMakeLists.txt:20 (find_package)
-- Configuring incomplete, errors occurred!
See also "C:/mpd/ympd/build/CMakeFiles/CMakeOutput.log".
Question:
How can i give cmake the parameters LIBMPDCLIENT_LIBRARY LIBMPDCLIENT_INCLUDE_DIR?
Project Structure:
mpd/ympd/
build/
cmake/
FindLibMPDClient.cmake
contrib/
htdocs/
libmpdclient-2.13/
.output/
libmpdclient-2.dll
src/
tools/
.travis
CMakeLlists
LICENSE
README
ympd.1
File FindLibMPDClient.cmake:
# - Try to find LibMPDClient
# Once done, this will define
#
# LIBMPDCLIENT_FOUND - System has LibMPDClient
# LIBMPDCLIENT_INCLUDE_DIRS - The LibMPDClient include directories
# LIBMPDCLIENT_LIBRARIES - The libraries needed to use LibMPDClient
# LIBMPDCLIENT_DEFINITIONS - Compiler switches required for using LibMPDClient
find_package(PkgConfig)
pkg_check_modules(PC_LIBMPDCLIENT QUIET libmpdclient)
set(LIBMPDCLIENT_DEFINITIONS ${PC_LIBMPDCLIENT_CFLAGS_OTHER})
find_path(LIBMPDCLIENT_INCLUDE_DIR
NAMES mpd/player.h
HINTS ${PC_LIBMPDCLIENT_INCLUDEDIR} ${PC_LIBMPDCLIENT_INCLUDE_DIRS}
)
find_library(LIBMPDCLIENT_LIBRARY
NAMES mpdclient
HINTS ${PC_LIBMPDCLIENT_LIBDIR} ${PC_LIBMPDCLIENT_LIBRARY_DIRS}
)
set(LIBMPDCLIENT_LIBRARIES ${LIBMPDCLIENT_LIBRARY})
set(LIBMPDCLIENT_INCLUDE_DIRS ${LIBMPDCLIENT_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibMPDClient DEFAULT_MSG
LIBMPDCLIENT_LIBRARY LIBMPDCLIENT_INCLUDE_DIR
)
mark_as_advanced(LIBMPDCLIENT_LIBRARY LIBMPDCLIENT_INCLUDE_DIR)
every help is appropriate, thanks

Rabbitmq-c library doesn't dynamically linked in Debian 8

The goal: make Rabbitmq-c dynamically linked via gcc (https://github.com/alanxz/rabbitmq-c).
Project is called storeman:
#include <stdarg.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <amqp_tcp_socket.h>
#include <amqp.h>
#include <amqp_framing.h>
#include <assert.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
int main(int argc, char const *const *argv)
{
amqp_connection_state_t conn;
conn=amqp_new_connection();
exit(0); //Everything else is deleted for testing
}
1. Download, compile and install library.
In new build folder inside rabbitmq-c download path:
cmake ..
cmake --build .
cmake -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
make install
Finally it does the following succesfull output:
[ 15%] Built target rabbitmq
...
[100%] Built target test_tables
Install the project...
-- Install configuration: "Release"
-- Up-to-date: /usr/local/lib/x86_64-linux-gnu/pkgconfig/librabbitmq.pc
-- Up-to-date: /usr/local/lib/x86_64-linux-gnu/librabbitmq.so.4.2.1
-- Up-to-date: /usr/local/lib/x86_64-linux-gnu/librabbitmq.so.4
-- Up-to-date: /usr/local/lib/x86_64-linux-gnu/librabbitmq.so
-- Up-to-date: /usr/local/lib/x86_64-linux-gnu/librabbitmq.a
-- Up-to-date: /usr/local/include/amqp.h
-- Up-to-date: /usr/local/include/amqp_framing.h
-- Up-to-date: /usr/local/include/amqp_tcp_socket.h
-- Up-to-date: /usr/local/include/amqp_ssl_socket.h
The library files are installed into
/usr/local/lib/x86_64-linux-gnu/ (librabbitmq.so and librabbitmq.so.4 points as links to librabbitmq.so.4.2.1, and there is librabbitmq.a)
/usr/local/include/, where all needed header files are resides (amqp.h
amqp_framing.h amqp_ssl_socket.h amqp_tcp_socket.h)
2. Use gcc.
gcc -Wall -I/usr/local/include -L/usr/local/lib/x86_64-linux-gnu -o
storeman storeman.c -lrabbitmq
GCC exits with:
error while loading shared libraries: librabbitmq.so.4: cannot open shared object file: No such file or directory
In the same time it may succesfully be compiled as static, using librabbitmq.a, that confuses me a lot... Will be very gratefull for any help.
It looks to me like the issue may be that file /etc/ld.so.conf.d/rabbitmq.conf is missing the .../lib/... subdirectory in its content. When I update that file's content to this it works for me (finds the rabbitmq shared lib):
/usr/local/lib/x86_64-linux-gnu
Note, run sudo ldconfig after saving the change.
This appears to be a rabbitmq git installation bug - I cloned and built from branch master on Feb 22, 2018 on Ubu-17.

CMake not compile on raspberry

I'm new with cmake.
With cmake I was able to compile my project on my laptop, but on the raspberry is not working.
This is the error i get on raspberry:
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.28")
-- checking for one of the modules 'glib-2.0'
-- Found GLib: /usr/lib/arm-linux-gnueabihf/libglib-2.0.so (found version "2.42.1")
-- Found mhd: /usr/include
CMake Error at cmake/FindGLIB.cmake:39 (add_library): add_library cannot create imported target "glib-2.0" because another target with the same name already exists.
Call Stack (most recent call first):librerie/CMakeLists.txt:2 (find_package)
-- Found GLib: /usr/lib/arm-linux-gnueabihf/libglib-2.0.so (found version "2.42.1")
-- Configuring incomplete, errors occurred!
See also "/home/pi/pl1/CMakeFiles/CMakeOutput.log".
This is my project structure:
src->
---- CMakeLists.txt
---- main.c
---- librerie->
-------------- CMakeLists.txt
-------------- cJSON.c
-------------- cJSON.h
-------------- config.c
-------------- config.h
-------------- server_web.c
-------------- server_web.h
-------------- funzioni_thread.c
-------------- funzioni_thread.h
---- cmake->
-------------- FindGLIB.cmake
-------------- FindMHD.cmake
This is First CMakeLists :
cmake_minimum_required (VERSION 2.6)
project (TestPL)
include_directories("${PROJECT_BINARY_DIR}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package(GLIB REQUIRED)
find_package(MHD REQUIRED)
add_subdirectory (librerie)
set (EXTRA_LIBS ${EXTRA_LIBS} librerie)
include_directories (${GLib_INCLUDE_DIRS} ${EXTRA_LIBS})
# add the executable
add_executable(TestPL main.c)
target_link_libraries (TestPL ${GLib_LIBRARY} ${MHD_LIBRARY} ${EXTRA_LIBS} m)
This is CMakeLists in librerie directory:
find_package(GLIB REQUIRED)
find_package(MHD REQUIRED)
include_directories (${GLib_INCLUDE_DIRS} ${EXTRA_LIBS})
add_library (librerie cJSON.c config.c generic.c server_web.c funzioni_thread.c)
target_link_libraries (librerie ${GLib_LIBRARY} ${MHD_LIBRARY})
What am I doing wrong?
You call twice
find_package(GLIB REQUIRED)
First time it is called from top-level CMakeLists.txt and defines glib-2.0 target. Second time it is called from librerie/CMakeLists.txt and attempt to create glib-2.0 again. That is why you see that error message: the target is already defined in this scope.
Possible workaround is to step into library subdirectory first, and only then call find_package() in top-level CMakeLists.txt:
add_subdirectory (librerie)
find_package(GLIB REQUIRED)
find_package(MHD REQUIRED)
Because IMPORTED targets has local visibility, glib-2.0 target defined by find_package(GLIB) call from subdirectory librerie/ will not be visible after returning from this subdirectory. So the second call from top-level directory will succeed.

Module for Tarantool, build error

I try write my module for tarantool:
https://github.com/agent-0007/mrasender
When i try compile it, i get error message:
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found TARANTOOL: /usr/include (found version "1.6.8-611-g944d005")
-- Tarantool LUADIR is share/tarantool
-- Tarantool LIBDIR is lib64/tarantool
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find MsgPuck (missing: MSGPUCK_INCLUDE_DIR MSGPUCK_LIBRARY)
Call Stack (most recent call first):
/usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
FindMsgPuck.cmake:13 (find_package_handle_standard_args)
CMakeLists.txt:18 (find_package)
What's wrong ?

Resources