下面我将介绍给出最少错误的解决方案.
在主要功能我包括
#include "APIenergy.h"
CMake文件
cmake_minimum_required(VERSION 3.3)project(TestProject)add_library( libAPIenergy SHARED importED )link_directorIEs (/home/I/lib/linux/x86)set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lAPIenergy ")set(SOURCE_fileS main.cpp APIenergy.h)add_executable(TestProject ${SOURCE_fileS})
和错误:
/home/I/clion-1.2/bin/cmake/bin/cmake --build /home/I/.Clion12/system/cmake/generated/9faec492/9faec492/DeBUG --target TestProject -- -j 8[ 50%] Building CXX object CMakefiles/TestProject.dir/main.cpp.o[100%] linking CXX executable TestProject/usr/bin/ld: cannot find -lAPIenergycollect2: error: ld returned 1 exit statusCMakefiles/TestProject.dir/build.make:94${PROJECT_SOURCE_DIR}/P2PTunnelAPIs.h.in": polecenia dla obIEktu 'TestProject' nIE powiodły sięmake[3]: *** [TestProject] Błąd 1CMakefiles/Makefile2:67: polecenia dla obIEktu 'CMakefiles/TestProject.dir/all' nIE powiodły sięmake[2]: *** [CMakefiles/TestProject.dir/all] Błąd 2CMakefiles/Makefile2:79: polecenia dla obIEktu 'CMakefiles/TestProject.dir/rule' nIE powiodły sięmake[1]: *** [CMakefiles/TestProject.dir/rule] Błąd 2Makefile:118: polecenia dla obIEktu 'TestProject' nIE powiodły sięmake: *** [TestProject] Błąd 2
我还使用我的共享库添加到系统PATH LD_liBRARY_PATH direcytory
export LD_liBRARY_PATH=$HOME/lib/linux/x86
.::编辑::. 1
我的CMake在你的消化之后
cmake_minimum_required(VERSION 3.3)project(TestProject)add_library(libAPIenergy SHARED importED)SET_PROPERTY(TARGET libAPIenergy PROPERTY importED_LOCATION /home/I/x86/libAPIenergy.so)target_link_librarIEs(TestProject libAPIEnergy)set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")set(SOURCE_fileS main.cpp APIenergy.h)add_executable(TestProject ${SOURCE_fileS})
来自CMake的错误
Error:Cannot specify link librarIEs for target "TestProject" which is not built by this project.
还有一件重要的事情.我用项目将APIenergy.h文件部署到主目录.
.::编辑2 ::.
cmake_minimum_required(VERSION 3.3)project(TestProject)add_library(libAPIenergy SHARED importED)target_link_librarIEs(TestProject libAPIenergy)SET_PROPERTY(TARGET libAPIenergy PROPERTY importED_LOCATION /home/I/lib/x86/libAPIenergy.so)set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")set(SOURCE_fileS main.cpp APIenergy.h)add_executable(TestProject ${SOURCE_fileS})target_link_librarIEs(TestProject libAPIenergy)
错误
Error:Cannot specify link librarIEs for target "TestProject" which is not built by this project.
.::编辑3 ::.
现在CMake文件没有错误
cmake_minimum_required(VERSION 3.3)project(TestProject)add_library(libAPIenergy SHARED importED)SET_PROPERTY(TARGET libAPIenergy PROPERTY importED_LOCATION /home/I/lib/x86/libAPIenergy.so)set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")set(SOURCE_fileS main.cpp APIenergy.h)add_executable(TestProject ${SOURCE_fileS})target_link_librarIEs(TestProject libAPIenergy)
简单地说我尝试过午餐的代码
#include <iostream>#include "APIenergy.h" // include without error this mean without underlinedusing namespace std;int main() { int ret = APIenergyInitialize(5); // IDE suggestions name function so is looks good cout << "Hello,World!" << endl; return 0;}
编译错误
/home/I/clion-1.2/bin/cmake/bin/cmake --build /home/I/.Clion12/system/cmake/generated/9faec492/9faec492/DeBUG0 --target TestProject -- -j 8[ 50%] linking CXX executable TestProject/home/I/lib/x86/libAPIenergy.so: error adding symbols: file in wrong formatcollect2: error: ld returned 1 exit statusCMakefiles/TestProject.dir/build.make:95: polecenia dla obIEktu 'TestProject' nIE powiodły sięmake[3]: *** [TestProject] Błąd 1CMakefiles/Makefile2:67: polecenia dla obIEktu 'CMakefiles/TestProject.dir/all' nIE powiodły sięmake[2]: *** [CMakefiles/TestProject.dir/all] Błąd 2CMakefiles/Makefile2:79: polecenia dla obIEktu 'CMakefiles/TestProject.dir/rule' nIE powiodły sięmake[1]: *** [CMakefiles/TestProject.dir/rule] Błąd 2Makefile:118: polecenia dla obIEktu 'TestProject' nIE powiodły sięmake: *** [TestProject] Błąd 2解决方法 如果要从源文件创建自己的库,请使用add_library.
如果要指定目标需要链接到其他人的库,请使用target_link_librarIEs.
总结以上是内存溢出为你收集整理的c 11 – Clion&CMake.如何添加库(* .so)全部内容,希望文章能够帮你解决c 11 – Clion&CMake.如何添加库(* .so)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)