CMake无法将Ultralight ui库正确链接到Clion 2019.1.2中的可执行文件

时间:2019-05-22 14:02:09

标签: c++ windows cmake clion

嗨,我正在尝试使用超轻型https://github.com/ultralight-ux/Ultralight构建基本应用。但是,构建在链接阶段失败。我经历了很多其他答案,但没有任何进展。

Cmake错误:

C:/Users/AMWAJ-PC/Desktop/untitled1/main.cpp:10: undefined reference to `__imp__ZN10ultralight3App6CreateEv'

C:/Users/AMWAJ-PC/Desktop/untitled1/main.cpp:11: undefined reference to `__imp__ZN10ultralight6Window6CreateEPNS_7MonitorEjjbj'
C:/Users/AMWAJ-PC/Desktop/untitled1/main.cpp:14: undefined reference to `__imp__ZN10ultralight7Overlay6CreateENS_3RefINS_6WindowEEEjjii'
C:/Users/AMWAJ-PC/Desktop/untitled1/main.cpp:15: undefined reference to `__imp__ZN10ultralight6StringC1EPKc'
C:/Users/AMWAJ-PC/Desktop/untitled1/main.cpp:15: undefined reference to `__imp__ZN10ultralight6StringD1Ev'
C:/Users/AMWAJ-PC/Desktop/untitled1/main.cpp:15: undefined reference to `__imp__ZN10ultralight6StringD1Ev'

Cmakelist.txt

cmake_minimum_required(VERSION 3.14)
project(untitled1)
set(CMAKE_CXX_STANDARD 17)

set(INCLUDE_DIRS "C:/C++/ultralight_ui/include/")
set(LINK_DIRS "C:/C++/ultralight_ui/lib/")
include_directories("${INCLUDE_DIRS}")
find_library(
    ULTRA_LIB
    NAMES UltralightCore AppCore Ultralight WebCore
    HINTS "${LINK_DIRS}")

add_executable(untitled1 main.cpp)
target_link_libraries(untitled1 ${ULTRA_LIB})

main.cpp

#include <AppCore/App.h>
#include <AppCore/Window.h>
#include <AppCore/Overlay.h>

using namespace ultralight;

int main()
{

auto app = App::Create();
auto window = Window::Create(app->main_monitor(), 300, 300, false, kWindowFlags_Titled);
window->SetTitle("Tutorial 2 - Basic App");
app->set_window(window);
auto overlay = Overlay::Create(window, window->width(), window->height(), 0, 0);
overlay->view()->LoadHTML("<center>Hello World!</center>");
app->Run();

return 0;
}

任何帮助都会对我有帮助:)谢谢

1 个答案:

答案 0 :(得分:1)

您错误地将NAMES参数用于find_library:此参数包含替代项的列表,并且find_library仅对单个库产生结果< / em>,其中有一个名称。

如果要找到多个库,则需要发出多个find_library命令,每个命令都有自己的名称(和自己的变量):

find_library(
    ULTRA_LIB_CORE
    NAMES UltralightCore
    HINTS ${LINK_DIRS})

find_library(
    ULTRA_LIB_APP_CORE
    NAMES AppCore
    HINTS ${LINK_DIRS})

find_library(
    ULTRA_LIB
    NAMES Ultralight
    HINTS ${LINK_DIRS})

find_library(
    ULTRA_LIB_WEB_CORE
    NAMES WebCore
    HINTS ${LINK_DIRS})

...

target_link_libraries(untitled1
    ${ULTRA_LIB_CORE} ${ULTRA_LIB_APP_CORE} ${ULTRA_LIB} ${ULTRA_LIB_WEB_CORE}
)