Note that there are some explanatory texts on larger screens.

plurals
  1. POCMake linking problem
    primarykey
    data
    text
    <p>I am trying to use CMake to compile a C++ application that uses the C library GStreamer.</p> <p>My main.cpp file looks like this:</p> <pre><code>extern "C" { #include &lt;gst/gst.h&gt; #include &lt;glib.h&gt; } int main(int argc, char* argv[]) { GMainLoop *loop; GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink; GstBus *bus; /* Initialisation */ gst_init (&amp;argc, &amp;argv); return 0; } </code></pre> <p>This works:</p> <pre><code>g++ -Wall $(pkg-config --cflags --libs gstreamer-0.10) main.cpp -o MPEG4GStreamer </code></pre> <p>How to I make it with CMake? My CMakeLists.txt file looks like this:</p> <pre><code>cmake_minimum_required (VERSION 2.6) project (MPEG4GStreamer) add_executable (MPEG4GStreamer main.cpp) include(${CMAKE_ROOT}/Modules/FindPkgConfig.cmake) # Set CMAKE_C_FLAGS variable with info from pkg-util execute_process(COMMAND pkg-config --cflags gstreamer-0.10 OUTPUT_VARIABLE CMAKE_C_FLAGS) string(REPLACE "\n" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) message("CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") # Set CMAKE_LINKER_FLAGS variable with info from pkg-util execute_process(COMMAND pkg-config --libs gstreamer-0.10 OUTPUT_VARIABLE CMAKE_LINKER_FLAGS) string(REPLACE "\n" "" CMAKE_LINKER_FLAGS ${CMAKE_LINKER_FLAGS}) message("CMAKE_LINKER_FLAGS: ${CMAKE_LINKER_FLAGS}") set_target_properties(MPEG4GStreamer PROPERTIES COMPILE_FLAGS ${CMAKE_C_FLAGS} LINKER_FLAGS ${CMAKE_LINKER_FLAGS}) </code></pre> <p>Output give a linker error:</p> <pre><code>~ $ cmake . CMAKE_C_FLAGS: -D_REENTRANT -I/usr/include/libxml2 -I/opt/local/include/gstreamer-0.10 -I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include CMAKE_LINKER_FLAGS: -L/opt/local/lib -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lxml2 -lpthread -lz -lm -lglib-2.0 -lintl -liconv -- Configuring done -- Generating done -- Build files have been written to: /Users/francis/ ~ $ make Linking CXX executable MPEG4GStreamer Undefined symbols: "_gst_init", referenced from: _main in main.cpp.o ld: symbol(s) not found collect2: ld returned 1 exit status make[2]: *** [MPEG4GStreamer] Error 1 make[1]: *** [CMakeFiles/MPEG4GStreamer.dir/all] Error 2 make: *** [all] Error 2 ~ $ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload