使用静态库编译

时间:2015-07-17 16:56:36

标签: c++ eclipse opencv static-libraries static-linking

我正在尝试使用静态库编译两个C ++项目,Eclipse C ++在ubuntu 14.04.2上运行。通过从终端编写以下命令,我已经实现了第一个目的:

  

g ++ -o example main.cpp -static

现在,如果我写“ldd example”,我得到的答案是:“它不是动态可执行文件”

但是,第二个项目是使用OpenCV(v 2.4.9)库。因此,上一个命令无法创建静态可执行文件。我也尝试了其他如:

  

g ++ -o example main.cpp -static pkg-config --static --libs opencv

     

g ++ -o example main.cpp pkg-config --static --libs opencv

但第一个不起作用(libcalib3d.so中的错误),第二个创建可执行文件,但有很多库依赖。谁能帮我?如果需要其他信息,请告诉我,我将编辑该帖子。谢谢!

编辑: 在终端写这个:pkg-config --static --libs opencv

我获得的输出如下:

  

/usr/local/lib/libopencv_calib3d.so   /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so   /usr/local/lib/libopencv_features2d.so   /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so   /usr/local/lib/libopencv_highgui.so   /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so   /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so   /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_ocl.so   /usr/local/lib/libopencv_photo.so   /usr/local/lib/libopencv_stitching.so   /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a   /usr/local/lib/libopencv_video.so   /usr/local/lib/libopencv_videostab.so -lrt -lpthread -lm -ldl

编辑2: opencv.pc文件包含以下行

  

prefix = / usr exec_prefix = $ {prefix}   LIBDIR = $ {PREFIX} / lib目录/ x86_64的-Linux的GNU   includedir_old = $ {前缀} /包含/ OpenCV的   includedir_new = $ {前缀} /包括

     

名称:OpenCV描述:开源计算机视觉库版本:   2.4.8 Libs:-L $ {libdir} $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_calib3d.so   -lopencv_calib3d $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_contrib.so   -lopencv_contrib $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_core.so -lopencv_core $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_features2d.so   -lopencv_features2d $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_flann.so-lopencv_flann   $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_gpu.so -lopencv_gpu   $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_highgui.so   -lopencv_highgui $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_imgproc.so   -lopencv_imgproc $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_legacy.so   -lopencv_legacy $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_ml.so -lopencv_ml $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_objdetect.so -lopencv_objdetect $ {exec_prefix} / lib / x86_64-linux-gnu /libopencv_ocl.so -lopencv_ocl   $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_photo.so -lopencv_photo   $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_stitching.so   -lopencv_stitching $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_superres.so   -lopencv_superres $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_ts.so -lopencv_ts $ {exec_prefix} /lib/x86_64-linux-gnu/libopencv_video.so -lopencv_video $ {exec_prefix} / lib / x86_64-linux-gnu /libopencv_videostab.so   -lopencv_videostab Cflags:-I $ {includedir_old} -I $ {includedir_new}

0 个答案:

没有答案