我按照這個答案為一個簡單的 Makefile 創建了一個 CMakeLists.txt
生成檔案
CC = g
INCFLAGS = -I/usr/local/include/embree3
LDFLAGS = -L"/usr/local/lib/" -lembree3
RM = /bin/rm -f
all:
$(CC) -o main main.cpp $(INCFLAGS) $(LDFLAGS)
clean:
$(RM) *.o main
CMakeLists.txt
cmake_minimum_required(VERSION 3.1.0)
project(aaf_project_impl)
include_directories(/usr/local/include/embree3) # -I flags for compiler
link_directories(/usr/local/lib/) # -L flags for linker
add_executable(main main.cpp)
target_link_libraries(main embree) # -l flags for linking prog target
Makefile 編譯正確,可執行檔案運行沒有任何問題。并使用 cmake 檔案,我執行以下操作(假設我在源目錄中)
- mkdir 構建
- 光碟構建
- ..
- 制作
在make第4步中引發以下錯誤
main.cpp:4:10: fatal error: 'embree3/rtcore.h' file not found
#include <embree3/rtcore.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/main.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
我通過克隆 git repo 從源代碼安裝了embree。我正在使用 Macbook M1 (MacOS Big Sur 11.5.1)。
我對 cmake 很陌生(一天前開始使用它)所以如果這是一個相當愚蠢的問題,我深表歉意。
uj5u.com熱心網友回復:
好的,所以按照您對我的評論的回答,問題是由于您通過 embree3 開始包含指令(這對于避免名稱沖突是有意義的),cmake 應該將包含 embree3 安裝的目錄作為包含目錄,而不是 embree3 檔案夾本身.
這就是 include_directories(/usr/local/include) 作業而不是 include_directories(/usr/local/include/embree3) 的原因。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/331759.html
