从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
在网上搜了好久但是都没有解决,大家知道这是怎么回事吗?
CMakeLists.txt ファイル https://github.com/openglredbook/examples/blob/master/CMakeLists.txt#L26 の 26 行目で、
GL rt dl
を削除すると、make が成功します。 。このサンプルをダウンロードしました。Windows で正常に実行できます。
図に示すように:
cmake の make プロセスでは Visual2013 が選択されています。
Visual Studio 2013 を使用してプロジェクトを開いてコンパイルします
これらの不要なエラーを無視し、bin フォルダーを開くと、多数の実行可能ファイルがあることも確認できます
これらの実行可能ファイルを開きます
あなたのプラットフォームは Mac なので、公式 Web サイトには cmake Unix makefile を使用するとも記載されていますも正常に実行できます。私と同じように、公式 Web サイトにアクセスして cmake の gui バージョンをダウンロードし、Mac OSX を選択します。次に、正しいパスを入力し、使用するジェネレーターを構成します。私は Visual 2013 を使用したいので、Visual 2013 を選択しました。自分の状況に応じて選択する必要があります。
次にジェネレーターを開いてプロジェクト全体を作成すると、最終的に実行可能ファイルが bin ディレクトリに生成されます。仕上げる!
アスダスダスド