Simple boost program with nvcc - error: declaration does not declare anything [-fpermissive]

Simple boost program with nvcc - error: declaration does not declare anything [-fpermissive]

背景

我想用boost库在cuda中序列化一些对象。我有一个更大的 Makefile,nvcc 编译了大约 20 个文件。我希望使用 boost 库编写 Makefile 的最小工作示例,然后将其添加到我更大的 makefile

促进图书馆本地化

生成文件

LIBS=--relocatable-device-code=true -lcusolver -lcusparse 
ARCH=-arch=sm_30
OPTIONS= -O2



hello: main.o 
    nvcc $(OPTIONS) $(ARCH) $(LIBS) -L${BOOST_ROOT}/lib/ -llibboost main.o -o hello 

main.o: main.cpp
    nvcc $(OPTIONS) $(ARCH) $(LIBS) -c main.cpp -o main.o
    

clean:
    rm -rf *.o hello.*

main.cpp

#include <iostream>
#include <boost/optional.hpp>
using namespace std;


int main() {

    boost::optional<string>;

    return 0;
}

运行 make hello && ./hello

我得到的错误

[ test]$ make hello && ./hello
nvcc -O2 -arch=sm_30 --relocatable-device-code=true -lcusolver -lcusparse  -c main.cpp -o main.o
main.cpp: In function ‘int main()’:
main.cpp:8:12: error: declaration does not declare anything [-fpermissive]
     boost::optional<string>;
            ^
make: *** [main.o] Error

您还没有为您的变量命名。尝试将其更改为:

boost::optional<string> exampleName;