1

我确定我错过了一些微不足道的东西,但我无法确定是什么。

我正在使用 CLion 构建一个包含四个外部库的项目。我正在尝试链接 Eigen、GLEW、GLFW 和 libigl。我在 VS 2015 中使用 VC++ 编译器。

这是我的 cmake 文件的一个迭代:

cmake_minimum_required(VERSION 3.9)
project(Lab1)

set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_CXX_STANDARD 17)

add_executable(Lab1 main.cpp)

include_directories(external/libigl/include)
include_directories(external/glfw/include/)
include_directories(external/eigen-git-mirror/)

include_directories(external/glew_2_1_0/include)

INCLUDE_DIRECTORIES(external/glew_2_1_0/lib/Release/x64)
link_libraries(external/glew_2_1_0/lib/Release/x64)

我已将 glew 库(32 位和 64 位)添加到 VC++ 中它们各自的文件夹中。我还将 glew32.dll 文件(64 位和 32 位)添加到系统文件夹中各自的文件夹中。如果我定义在我的 Cmake 文件中查找它们的位置,我认为我不需要这样做,但我并不完全确定。

这是我在 CLion 中的文件夹结构: CLion 文件夹结构。

以下是 main.cpp 包含的内容,以防万一:

#include <igl/readOFF.h>
#include <igl/viewer/Viewer.h>

Eigen::MatrixXd V;
Eigen::MatrixXi F;

int main(int argc, char *argv[])
{
    // Load a mesh in OFF format
    igl::readOFF("bunny.off", V, F);

    // Plot the mesh
    igl::viewer::Viewer viewer;
    viewer.data.set_mesh(V, F);
    viewer.launch();
}

这些是我得到的链接器错误。

[100%] Linking CXX executable Lab1.exe
    "D:\Actual Program Files\JetBrains\CLion 2017.3.1\bin\cmake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\Lab1.dir --manifests  -- D:\ACTUAL~1\VISUAL~2\VC\bin\link.exe /nologo @CMakeFiles\Lab1.dir\objects1.rsp @C:\Users\Mohammed\AppData\Local\Temp\nm6742.tmp
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glBindTexture@8 referenced in function "public: void __thiscall igl::viewer::OpenGL_state::bind_mesh(void)" (?bind_mesh@OpenGL_state@viewer@igl@@QAEXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glBlendFunc@8 referenced in function "public: void __thiscall igl::viewer::ViewerCore::draw(class igl::viewer::ViewerData &,class igl::viewer::OpenGL_state &,bool)" (?draw@ViewerCore@viewer@igl@@QAEXAAVViewerData@23@AAVOpenGL_state@23@_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "public: void __thiscall igl::viewer::ViewerCore::clear_framebuffers(void)" (?clear_framebuffers@ViewerCore@viewer@igl@@QAEXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function "public: void __thiscall igl::viewer::ViewerCore::clear_framebuffers(void)" (?clear_framebuffers@ViewerCore@viewer@igl@@QAEXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glDeleteTextures@8 referenced in function "public: void __thiscall igl::viewer::OpenGL_state::free_buffers(void)" (?free_buffers@OpenGL_state@viewer@igl@@QAEXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glDisable@4 referenced in function "public: void __thiscall igl::viewer::ViewerCore::draw(class igl::viewer::ViewerData &,class igl::viewer::OpenGL_state &,bool)" (?draw@ViewerCore@viewer@igl@@QAEXAAVViewerData@23@AAVOpenGL_state@23@_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glDrawElements@16 referenced in function "public: void __thiscall igl::viewer::OpenGL_state::draw_mesh(bool)" (?draw_mesh@OpenGL_state@viewer@igl@@QAEX_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function "public: void __thiscall igl::viewer::ViewerCore::draw(class igl::viewer::ViewerData &,class igl::viewer::OpenGL_state &,bool)" (?draw@ViewerCore@viewer@igl@@QAEXAAVViewerData@23@AAVOpenGL_state@23@_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glGenTextures@8 referenced in function "public: void __thiscall igl::viewer::OpenGL_state::init_buffers(void)" (?init_buffers@OpenGL_state@viewer@igl@@QAEXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glGetError@0 referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glGetString@4 referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glLineWidth@4 referenced in function "public: void __thiscall igl::viewer::ViewerCore::draw(class igl::viewer::ViewerData &,class igl::viewer::OpenGL_state &,bool)" (?draw@ViewerCore@viewer@igl@@QAEXAAVViewerData@23@AAVOpenGL_state@23@_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glPixelStorei@8 referenced in function "public: void __thiscall igl::viewer::OpenGL_state::bind_mesh(void)" (?bind_mesh@OpenGL_state@viewer@igl@@QAEXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glPointSize@4 referenced in function "public: void __thiscall igl::viewer::ViewerCore::draw(class igl::viewer::ViewerData &,class igl::viewer::OpenGL_state &,bool)" (?draw@ViewerCore@viewer@igl@@QAEXAAVViewerData@23@AAVOpenGL_state@23@_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glPolygonMode@8 referenced in function "public: void __thiscall igl::viewer::OpenGL_state::draw_mesh(bool)" (?draw_mesh@OpenGL_state@viewer@igl@@QAEX_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glPolygonOffset@8 referenced in function "public: void __thiscall igl::viewer::OpenGL_state::draw_mesh(bool)" (?draw_mesh@OpenGL_state@viewer@igl@@QAEX_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glTexImage2D@36 referenced in function "public: void __thiscall igl::viewer::OpenGL_state::bind_mesh(void)" (?bind_mesh@OpenGL_state@viewer@igl@@QAEXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glTexParameteri@12 referenced in function "public: void __thiscall igl::viewer::OpenGL_state::bind_mesh(void)" (?bind_mesh@OpenGL_state@viewer@igl@@QAEXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function "public: void __thiscall igl::viewer::ViewerCore::draw(class igl::viewer::ViewerData &,class igl::viewer::OpenGL_state &,bool)" (?draw@ViewerCore@viewer@igl@@QAEXAAVViewerData@23@AAVOpenGL_state@23@_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glewInit@0 referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glewGetErrorString@4 referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glewGetString@4 referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwTerminate referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwSetErrorCallback referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwGetPrimaryMonitor referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwGetVideoMode referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwWindowHint referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwCreateWindow referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwDestroyWindow referenced in function "public: void __thiscall igl::viewer::Viewer::launch_shut(void)" (?launch_shut@Viewer@viewer@igl@@QAEXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwWindowShouldClose referenced in function "public: bool __thiscall igl::viewer::Viewer::launch_rendering(bool)" (?launch_rendering@Viewer@viewer@igl@@QAE_N_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwSetWindowShouldClose referenced in function "void __cdecl glfw_key_callback(struct GLFWwindow *,int,int,int,int)" (?glfw_key_callback@@YAXPAUGLFWwindow@@HHHH@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwGetWindowSize referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwGetFramebufferSize referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwGetWindowAttrib referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwSetWindowSizeCallback referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwPollEvents referenced in function "public: bool __thiscall igl::viewer::Viewer::launch_rendering(bool)" (?launch_rendering@Viewer@viewer@igl@@QAE_N_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwWaitEvents referenced in function "public: bool __thiscall igl::viewer::Viewer::launch_rendering(bool)" (?launch_rendering@Viewer@viewer@igl@@QAE_N_N@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwSetInputMode referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwSetKeyCallback referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwSetCharModsCallback referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwSetMouseButtonCallback referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwSetCursorPosCallback referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwSetScrollCallback referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwSetDropCallback referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwMakeContextCurrent referenced in function "public: int __thiscall igl::viewer::Viewer::launch_init(bool,bool)" (?launch_init@Viewer@viewer@igl@@QAEH_N0@Z)
main.cpp.obj : error LNK2019: unresolved external symbol _glfwSwapBuffers referenced in function "public: bool __thiscall igl::viewer::Viewer::launch_rendering(bool)" (?launch_rendering@Viewer@viewer@igl@@QAE_N_N@Z)
main.cpp.obj : error LNK2001: unresolved external symbol ___glewActiveTexture
main.cpp.obj : error LNK2001: unresolved external symbol ___glewBindBuffer
main.cpp.obj : error LNK2001: unresolved external symbol ___glewBufferData
main.cpp.obj : error LNK2001: unresolved external symbol ___glewDeleteBuffers
main.cpp.obj : error LNK2001: unresolved external symbol ___glewGenBuffers
main.cpp.obj : error LNK2001: unresolved external symbol ___glewAttachShader
main.cpp.obj : error LNK2001: unresolved external symbol ___glewCompileShader
main.cpp.obj : error LNK2001: unresolved external symbol ___glewCreateProgram
main.cpp.obj : error LNK2001: unresolved external symbol ___glewCreateShader
main.cpp.obj : error LNK2001: unresolved external symbol ___glewDeleteProgram
main.cpp.obj : error LNK2001: unresolved external symbol ___glewDeleteShader
main.cpp.obj : error LNK2001: unresolved external symbol ___glewDisableVertexAttribArray
main.cpp.obj : error LNK2001: unresolved external symbol ___glewEnableVertexAttribArray
main.cpp.obj : error LNK2001: unresolved external symbol ___glewGetAttribLocation
main.cpp.obj : error LNK2001: unresolved external symbol ___glewGetProgramInfoLog
main.cpp.obj : error LNK2001: unresolved external symbol ___glewGetProgramiv
main.cpp.obj : error LNK2001: unresolved external symbol ___glewGetShaderInfoLog
main.cpp.obj : error LNK2001: unresolved external symbol ___glewGetShaderiv
main.cpp.obj : error LNK2001: unresolved external symbol ___glewGetUniformLocation
main.cpp.obj : error LNK2001: unresolved external symbol ___glewLinkProgram
main.cpp.obj : error LNK2001: unresolved external symbol ___glewShaderSource
main.cpp.obj : error LNK2001: unresolved external symbol ___glewUniform1f
main.cpp.obj : error LNK2001: unresolved external symbol ___glewUniform1i
main.cpp.obj : error LNK2001: unresolved external symbol ___glewUniform3fv
main.cpp.obj : error LNK2001: unresolved external symbol ___glewUniform4f
main.cpp.obj : error LNK2001: unresolved external symbol ___glewUniformMatrix4fv
main.cpp.obj : error LNK2001: unresolved external symbol ___glewUseProgram
main.cpp.obj : error LNK2001: unresolved external symbol ___glewVertexAttribPointer
main.cpp.obj : error LNK2001: unresolved external symbol ___glewBindFragDataLocation
main.cpp.obj : error LNK2001: unresolved external symbol ___glewProgramParameteri
main.cpp.obj : error LNK2001: unresolved external symbol ___glewBindVertexArray
main.cpp.obj : error LNK2001: unresolved external symbol ___glewDeleteVertexArrays
main.cpp.obj : error LNK2001: unresolved external symbol ___glewGenVertexArrays
main.cpp.obj : error LNK2001: unresolved external symbol _glewExperimental
Lab1.exe : fatal error LNK1120: 81 unresolved externals
LINK Pass 1 failed. with 1120
NMAKE : fatal error U1077: '"D:\Actual Program Files\JetBrains\CLion 2017.3.1\bin\cmake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"D:\Actual Program Files\Visual Studio 2015\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"D:\Actual Program Files\Visual Studio 2015\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"D:\Actual Program Files\Visual Studio 2015\VC\BIN\nmake.exe"' : return code '0x2'
Stop. 

谢谢您的帮助。


编辑: Tsyvarev 帮我解决了明显的错误。也将所有内容更改为 32 位。减少到 47 个未解决的外部因素。工作后会更新。当前的 Cmake:

cmake_minimum_required(VERSION 3.9)
project(Lab1)

set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_CXX_STANDARD 17)

link_libraries(../external/glew_2_1_0/lib/Release/Win32/glew32s)


add_executable(Lab1 main.cpp)


include_directories(external/libigl/include)
include_directories(external/glfw/include/)
include_directories(external/eigen-git-mirror/)

include_directories(external/glew_2_1_0/include)

编辑解决一切正常!缺少一些库。决定在本地链接它们。这是遇到此问题的下一个倾倒灵魂的 cmake:

cmake_minimum_required(VERSION 3.9)
project(Lab1)

set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_CXX_STANDARD 17)

link_libraries(../external/glew_2_1_0/lib/Release/Win32/glew32s)
link_libraries(../external/glfw/lib-vc2015/glfw3)

link_libraries(../external/openGL/OPENGL32)
link_libraries(../external/openGL/glut32)
link_libraries(../external/openGL/glu32)

find_package(OpenGL REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS})
#target_link_libraries(${PROJECTNAME} ${OPENGL_LIBRARIES})




add_executable(Lab1 main.cpp)


include_directories(external/libigl/include)
include_directories(external/glfw/include/)
include_directories(external/eigen-git-mirror/)

include_directories(external/glew_2_1_0/include)

谢谢您的帮助!

4

1 回答 1

1

命令link_libraries只影响进一步的目标,所以它应该在调用之前 add_executable发出。


此外,link_libraries接受库文件,而不是包含它们的目录。

于 2018-01-26T20:34:48.547 回答