suchen

Heim  >  Fragen und Antworten  >  Hauptteil

c++ - ld: library not found for -lGL on Mac

从https://github.com/openglredbook/examples 下载了OpenGL编程指南的样例代码,但是运行的时候报错,在build文件夹运行cmake .. 报错如下(运行环境是Mac):

-- Try OpenMP C flag = [-fopenmp=libomp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [ ]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [/openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-Qopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-xopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [+Oopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-qsmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-mp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-fopenmp=libomp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [ ]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [/openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-Qopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-openmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-xopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [+Oopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-qsmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP CXX flag = [-mp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Could NOT find OpenMP (missing:  OpenMP_C_FLAGS OpenMP_CXX_FLAGS)
-- Using Cocoa for window creation
-- Using NSGL for context creation
-- Building GLFW only for the native architecture
-- Configuring done
-- Generating done

然后运行make 报错如下:

[  6%] Built target vermilion
[ 15%] Built target glfw
[ 16%] Linking CXX executable ../bin/12-imageprocessing
ld: library not found for -lGL
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [../bin/12-imageprocessing] Error 1
make[1]: *** [CMakeFiles/12-imageprocessing.dir/all] Error 2
make: *** [all] Error 2

在网上搜了好久但是都没有解决,大家知道这是怎么回事吗?

迷茫迷茫2768 Tage vor1087

Antworte allen(3)Ich werde antworten

  • 迷茫

    迷茫2017-04-17 15:40:08

    问题已解决,CMakeLists.txt 文件26行https://github.com/openglredbook/examples/blob/master/CMakeLists.txt#L26 处,删除GL rt dl即可make成功。

    Antwort
    0
  • 黄舟

    黄舟2017-04-17 15:40:08

    我去下载了这个例子,在windows下能成功运行。
    如图:
    cmake 的make过程 选择的是visual2013 官方也说了visual 2013是可以的

    使用visual studio 2013 打开项目编译

    忽略这些不必要的错误,打开bin文件夹,也可看到有很多可执行文件

    打开这些可执行文件

    因为你的是mac平台,官网也说了使用cmake Unix makefiles 也是可以成功运行的。你可以和我一样去官网下载一个cmake的gui版,你选择Mac OSX。然后输入正确路径,配置你要用到的generator,因为我要用到visual 2013 于是我选择了visual 2013.你 要根据你自己的情况选择。

    然后打开你的generator去make整个项目,最后会在bin目录下生成可执行文件。完成!

    Antwort
    0
  • 迷茫

    迷茫2017-04-17 15:40:08

    asdasdasd

    Antwort
    0
  • StornierenAntwort