c++ - Clion 无法链接找到的库,而手动编译工作
问题描述
我正在尝试使用 Clion 在 macos 上创建一个跨平台的 openGL 应用程序。Cmake 脚本正确找到了 assimp 库,但无法链接它。
我尝试重新安装 assimp,然后重新编译它。接下来我检查了手动编译是否可以完成这项工作(令人惊讶的是)。
这是命令:(clang main.cpp -std=c++11 -framework OpenGL -lglfw -lassimp -lglew -o main
它也适用于 g++)。
这是我的 CmakeList.txt:
cmake_minimum_required(VERSION 3.12)
project(OpenGlSetup)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/Modules/")
message(CMAKE_MODULE_PATH : ${PROJECT_SOURCE_DIR}/Modules/)
set(SOURCE_FILES main.cpp)
add_executable(OpenGlSetup ${SOURCE_FILES})
find_package(ASSIMP REQUIRED)
IF (NOT ASSIMP_FOUND)
message(WARNING ASSIMP-NOT-FOUND : ${ASSIMP_INCLUDE_DIRS})
ENDIF()
*** rest of the libraries are loaded in the same way, and they load properly (project compiles and run provided i remove assimp parts) **
include_directories(${OPENGL_INCLUDE_DIR} ${GLM_INCLUDE_DIRS} ${ASSIMP_INCLUDE_DIRS})
link_directories(${ASSIMP_INCLUDE_DIRS})
target_link_libraries(OpenGlSetup ${OPENGL_LIBRARY} ${GLEW_LIBRARY} ${ASSIMP_LIBRARIES} glfw)
这是我的应用程序:
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <cmath>
#include <assimp/scene.h>
#include <assimp/Importer.hpp>
static void glfwError(int id, const char* description)
{
std::cout << description << std::endl;
}
int main(int argc, char *argv[]) {
if (!glfwInit()) {
printf("failed to initialize GLFW.\n");
return -1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
auto window = glfwCreateWindow(1000, 600, "awesome", nullptr, nullptr);
if (!window) {
return -1;
}
glfwMakeContextCurrent(window);
if (glewInit()) {
printf("failed to initialize OpenGL\n");
return -1;
}
printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
while(!glfwWindowShouldClose(window)) {
glClearColor(0.f,
0.f,
1.f,
1.f
);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
};
Assimp::Importer importer;
aiScene* scene;
return 0;
}
错误:
[ 50%] Building CXX object CMakeFiles/OpenGlSetup.dir/main.cpp.o
[100%] Linking CXX executable OpenGlSetup
ld: library not found for -lassimp
clang: error: linker command failed with exit code 1 (use -v to see. invocation)
make[3]: *** [OpenGlSetup] Error 1
make[2]: *** [CMakeFiles/OpenGlSetup.dir/all] Error 2
make[1]: *** [CMakeFiles/OpenGlSetup.dir/rule] Error 2
make: *** [OpenGlSetup] Error 2
解决方案
推荐阅读
- html - 椭圆进度条|| 饼形图
- c# - 为什么实体框架不能识别数据库中的现有记录?
- javascript - 我的 recaptcha 渲染不起作用并返回 0
- c# - 在 C# 中处理空值 - 将 Excel 数据表上传到数据库
- html - Flutter:如何在 webview 中显示本地 html 文件?
- video-streaming - 在 HLS 中提供相同音频再现的多种编码
- docker - 无法连接到 Kubernetes 的 ETCD
- arrays - 生成相邻元素不是 x+1 的二维数组
- arrays - 在 for 循环中选择数组的特定行
- ios - 如何将 AppClip 添加到 Siri 的附近建议?