Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ CMake链接问题_C++_Linker_Executable_Cmake_Gstreamer - Fatal编程技术网

C++ CMake链接问题

C++ CMake链接问题,c++,linker,executable,cmake,gstreamer,C++,Linker,Executable,Cmake,Gstreamer,我尝试使用CGEL编译一个C++应用程序,使用C库gStuff.< /P> 我的main.cpp文件如下所示: extern "C" { #include <gst/gst.h> #include <glib.h> } int main(int argc, char* argv[]) { GMainLoop *loop; GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink; Gs

我尝试使用CGEL编译一个C++应用程序,使用C库gStuff.< /P> 我的main.cpp文件如下所示:

extern "C" {
#include <gst/gst.h>
#include <glib.h>
}


int main(int argc, char* argv[])
{
  GMainLoop *loop;

  GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink;
  GstBus *bus;

  /* Initialisation */
  gst_init (&argc, &argv);
  return 0;
}
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})
如何使用CMake制作?我的CMakeLists.txt文件如下所示:

extern "C" {
#include <gst/gst.h>
#include <glib.h>
}


int main(int argc, char* argv[])
{
  GMainLoop *loop;

  GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink;
  GstBus *bus;

  /* Initialisation */
  gst_init (&argc, &argv);
  return 0;
}
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})
输出提示链接器错误:

~ $ 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
~ $

Doh,只需要用CMAKE_EXE_LINKER_标志替换CMAKE_LINKER_标志。

您应该找到库gstreamer-0.10,并使用目标链接库将其链接到您的目标。您需要一个FindGStream.cmake模块,下面是我通过谷歌搜索找到的一个模块:

有了这样的模块,您可能需要这样的内容:

extern "C" {
#include <gst/gst.h>
#include <glib.h>
}


int main(int argc, char* argv[])
{
  GMainLoop *loop;

  GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink;
  GstBus *bus;

  /* Initialisation */
  gst_init (&argc, &argv);
  return 0;
}
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})
包括(FindStreamer.cmake) include_目录(${GSTREAMER_include_DIR}) 添加定义(${GSTREAMER\u definitions})
目标链接库(MPEG4GStreamer${GSTREAMER\u libraries})

真正的问题是您键入了属性的名称,它是链接标志,而不是链接ER\u标志。您的解决方案只是一个变通办法。

那么您应该结束这个问题