C ++错误:使用Cmake在';'标记之前预期的primary-expression

时间:2017-02-13 07:41:35

标签: c++ cmake g++ cmake-gui

我使用Cmake来定义folder paths

我有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_FILEint 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; } 提供#define。

但是当我在main.cpp文件中使用它们时

/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;

我有错误

function removeclass(elementId, elementClass) {
    document.getElementById(elementId).className = document.getElementById(elementId).className.replace( ' '+elementClass , '' );
}

1 个答案:

答案 0 :(得分:1)

configure_file时,表达式

#cmakedefine CAFFE_MODEL_PATH

实际上是条件宏定义。也就是说,仅当相应的CMake变量被评估为 no-false (根据if(constant)规则)时才定义宏。

在您的情况下,CMake变量具有值,这些值被评估为false。如此配置的文件(在您的情况下为Config.h不包含宏定义

如果要使用字符串值定义宏,请使用

#define CAFFE_MODEL_PATH "@CAFFE_MODEL_PATH@"

即使相应的变量为空,也可以正确定义宏。

另请参阅documentation configure_file命令。