0
我使用Cmake
來定義folder paths
。C++錯誤:使用Cmake之前';'令牌的預期主表達式
我有Config.in.h
文件,其中#cmakedefine
被聲明爲
#cmakedefine CAFFE_MODEL_PATH
#cmakedefine CAFFE_MODEL_PATH
#cmakedefine CAFFE_TRAIN_MODEL
#cmakedefine MEAN_FILE
#cmakedefine LABEL_FILE
在我CMakeLists.txt
,我一樣
set(CAFFE_MODEL_PATH "" CACHE PATH "Path to a Caffe model")
set(CAFFE_TRAIN_MODEL "" CACHE PATH "Path to a trained model")
set(MEAN_FILE "" CACHE PATH "Path to the mean file all trained images")
set(LABEL_FILE "" CACHE PATH "Path to the mean file all trained images")
configure_file (
"${PROJECT_SOURCE_DIR}/Config.h.in"
"${PROJECT_SOURCE_DIR}/Config.h"
)
使Config.h
對那些CAFFE_MODEL_PATH, CAFFE_TRAIN_MODEL, MEAN_FILE, LABEL_FILE
的#define。
但是,當我在我的main.cpp文件中使用它們
int main(void) {
::google::InitGoogleLogging("endtoenddetection");
string model_file = CAFFE_MODEL_PATH;
string trained_file = CAFFE_TRAIN_MODEL;
string mean_file = MEAN_FILE;
string label_file = LABEL_FILE;
}
我有錯誤,因爲
/home/Softwares/ReInspect/endtoendLstm/main.cpp:8:43: error: expected primary-expression before ‘;’ token
string model_file = CAFFE_MODEL_PATH;
^
/home/Softwares/ReInspect/endtoendLstm/main.cpp:9:44: error: expected primary-expression before ‘;’ token
string trained_file = CAFFE_TRAIN_MODEL;
^
/home/Softwares/ReInspect/endtoendLstm/main.cpp:10:36: error: expected primary-expression before ‘;’ token
string mean_file = MEAN_FILE;
^
/home/Softwares/ReInspect/endtoendLstm/main.cpp:11:37: error: expected primary-expression before ‘;’ token
string label_file = LABEL_FILE;
你在'main.cpp'中有'#include'Config.h''嗎? – Barmar
'這樣Config.h就爲這些定義了# - 我想它對你所有的宏都有'/ * #undef VAR * /'(也就是說**並沒有定義它們)。這是因爲CMake中相應變量的內容是* empty *,它被CMake評爲* false *。有關命令'configure_file',請參見[documentation](https://cmake.org/cmake/help/v3.7/command/configure_file.html)。如果你想用(可能是空的)字符串值定義宏,可以在文件Config.h.in中使用'#define CAFFE_MODEL_PATH「@ CAFFE_MODEL_PATH @」'。 – Tsyvarev
是的,我包含main.cpp中的「Config.h」 – batuman