libpoly2tri.a没有使用target_link_libraries

时间:2016-05-24 09:57:38

标签: linux gcc cmake

项目CmakeCheckPrj中的main.cpp文件是:

#include <iostream>
#include "p3d_header.h"
#include "NameLibrary.h"
#include "poly2tri.h"

int main(void)
{
const auto name = p3d::NameLibrary::MATERIAL_ASSIGMENT_ATTR(); 
std::cout<<"The name library  returned :"<<name << std::endl;
std::vector<p2t::Point*> list;
p3d::Vector3 ver1(1.0,2.0);
p3d::Vector3 ver2(1.0,1.0);
p3d::Vector3 ver3(3.0,1.0);
p2t::Point* newPt = new p2t::Point(ver1.x,ver1.y);
p2t::Point* newPt1 = new p2t::Point(ver2.x,ver2.y);
p2t::Point* newPt2 = new p2t::Point(ver3.x,ver3.y);
list.push_back(newPt);
list.push_back(newPt1);
list.push_back(newPt2);

p2t::CDT patch1(list);
patch1.Triangulate();
std::vector<p2t::Triangle*> triList = patch1.GetTriangles();
return 0;

}

CmakeCheckPrj项目CmakeLists.txt是:

set(PROJ_NAME "CmakeCheckPrj")
project(${PROJ_NAME} CXX)

set(CUDA_FREE_CONFIG "TRUE" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -DCUDA_FREE")    

if("${LIB_PATH}" STREQUAL "")
    message("For now pelase set LIB_PATH as the path to p3d_projects folder")
else("${LIB_PATH}" NOT STREQUAL "")
    set(STATIC_LIB_PATH ${LIB_PATH}/p3d_build/linux/P3DInfrastructure/libP3DInfrastructure.a )
    message("The internal static library path is ${STATIC_LIB_PATH}")
endif()

FILE(GLOB SRCFILES "*.cpp")
FILE(GLOB HDRFILES "*.h")   

add_subdirectory(../P3DInfrastructure ../P3DInfrastructure)
Set(INC_DIR ../inc/linux_inc/poly2tri;../P3DInfrastructure;../abutil;) 

include_directories(${INC_DIR})
add_executable (CmakeCheckPrj ${SRCFILES} ${HDRFILES})
add_dependencies (CmakeCheckPrj P3DInfrastructure )

set(EXT_LIB_PATH ${LIB_PATH}/lib/linux_lib/debug/)
message("External Library Path is ${EXT_LIB_PATH}")

find_library(RESULT NAMES libpoly2tri.a PATHS ${EXT_LIB_PATH})
message("External Library Path found ${RESULT}")

target_link_libraries(CmakeCheckPrj ${RESULT})

cmake on generate正确查找库:

External Library Path is /igd/3dt/home/sbidarah/3DT_NEW_TAGGED/p3d_projects/lib/linux_lib/debug/
External Library Path found /igd/3dt/home/sbidarah/3DT_NEW_TAGGED/p3d_projects/lib/linux_lib/debug/libpoly2tri.a

构建CmakeCheckPrj时,会出现以下错误:

main.cpp:(.text+0x1f1): undefined reference to       `p2t::CDT::CDT(std::vector<p2t::Point*, std::allocator<p2t::Point*> >)'
main.cpp:(.text+0x20c): undefined reference to `p2t::CDT::Triangulate()'
main.cpp:(.text+0x222): undefined reference to `p2t::CDT::GetTriangles()'
main.cpp:(.text+0x242): undefined reference to `p2t::CDT::~CDT()'
main.cpp:(.text+0x287): undefined reference to `p2t::CDT::~CDT()'
collect2: error: ld returned 1 exit status

指向poly2tri的链接失败,因此未定义引用CDT类方法的错误。请帮助我知道我做错了什么以及将库链接到exe的正确方法是什么?

谢谢&amp;的问候,

0 个答案:

没有答案