c++ - ld: library not found for -lGL on Mac
迷茫
迷茫 2017-04-17 15:38:08
0
3
1107

从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

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

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
迷茫

The problem has been solved. At line 26 of the CMakeLists.txt file https://github.com/openglredbook/examples/blob/master/CMakeLists.txt#L26, delete GL rt dl and the make will be successful.

黄舟

I downloaded this example and it can run successfully under windows.
As shown in the picture:
The make process of cmake chose visual2013. The official also said that visual 2013 is acceptable

Use visual studio 2013 to open the project and compile

Ignore these unnecessary errors, open the bin folder, and you can also see that there are many executable files

Open these executable files

Because yours is a mac platform, the official website also said that using cmake Unix makefiles can also run successfully of. Like me, you can go to the official website to download a gui version of cmake, and you choose Mac OSX. Then enter the correct path and configure the generator you want to use. Because I want to use visual 2013, I chose visual 2013. You have to choose according to your own situation.

Then open your generator to make the entire project, and finally the executable file will be generated in the bin directory. Finish!

迷茫

asdasdasd

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template