尝试将外部库包含到CMAKE项目时链接错误

时间:2013-04-28 10:34:05

标签: dll cmake external

我目前尝试将外部动态链接库(dll)添加到我的cmake项目中。我有.dll和.lib文件。我花了很多时间自己找答案,但我找不到解决办法。包含工作但我在尝试编译最小解决方案时总是遇到链接错误。配置和生成CMAKE时不会抛出错误并找到库。我希望之前有人遇到问题并认出我的错误

我还构建了自己的find模块,看起来像这样

find_path(LLT_INCLUDE_DIR InterfaceLLT_2.h HINTS ${LLT_DIR})

find_library(LLT_LIBRARY NAMES LLT HINTS ${LLT_DIR} )

set(LLT_LIBRARIES ${LLT_LIBRARY} )

set(LLT_INCLUDE_DIRS ${LLT_INCLUDE_DIR} )

include(FindPackageHandleStandardArgs)

# handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE

# if all listed variables are TRUE

find_package_handle_standard_args(LLT  DEFAULT_MSG LLT_LIBRARY LLT_INCLUDE_DIR)

mark_as_advanced(LLT_INCLUDE_DIR LLT_LIBRARY )

相应的CMakeLists.txt看起来像这样

PROJECT(TestProg)

cmake_minimum_required(VERSION 2.8)

FIND_PACKAGE(LLT REQUIRED)

INCLUDE_DIRECTORIES(${LLT_INCLUDE_DIR})

SET(TestProg_SOURCES

main.cpp

)

SET(TestProg_HEADERS

)

add_executable(TestProg ${TestProg_SOURCES} ${TestProg_HEADERS})

target_link_libraries(TestProg ${LLT_LIBRARIES} )

这是CMAKE输出

The C compiler identification is MSVC 16.0.40219.1

The CXX compiler identification is MSVC 16.0.40219.1

Check for working C compiler using: Visual Studio 10

Check for working C compiler using: Visual Studio 10 -- works

Detecting C compiler ABI info

Detecting C compiler ABI info - done

Check for working CXX compiler using: Visual Studio 10

Check for working CXX compiler using: Visual Studio 10 -- works

Detecting CXX compiler ABI info

Detecting CXX compiler ABI info - done

Found LLT: C:/XXX/LLT.lib

Configuring done

Generating done 

这是codesnippet。我真的不知道你对链接命令的意思,还是我在代码中忘记了什么?

#include <iostream>
#include "InterfaceLLT_2.h"
using namespace std;

int main()
{

    bool bLoadError;

    CInterfaceLLT* m_pLLT;

     m_pLLT = new CInterfaceLLT("LLT.dll", &bLoadError);

     cout << "Hello World!" << endl;



    return 0;
}

0 个答案:

没有答案