Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 本机生成使用gradle失败_C++_Visual Studio 2012_Gradle - Fatal编程技术网

C++ 本机生成使用gradle失败

C++ 本机生成使用gradle失败,c++,visual-studio-2012,gradle,C++,Visual Studio 2012,Gradle,我正试图从格雷德尔转到马文。下面是我简单的hello world示例构建。我的毕业设计如下:- apply plugin: 'cpp' model { components { main(NativeExecutableSpec) {} } } 我有一个cpp文件和一个h文件。目录结构如下所示:- src/main/cpp/HelloWorld.cpp src/main/headers/HelloWorld.h // Hello.h #if defined(_WIN3

我正试图从格雷德尔转到马文。下面是我简单的hello world示例构建。我的毕业设计如下:-

apply plugin: 'cpp'

model {
    components {
    main(NativeExecutableSpec) {}
  }
}
我有一个cpp文件和一个h文件。目录结构如下所示:-

src/main/cpp/HelloWorld.cpp
src/main/headers/HelloWorld.h
// Hello.h

#if defined(_WIN32) && defined(DLL_EXPORT)
#define LIB_FUNC __declspec(dllexport)
#else
#define LIB_FUNC
#endif

class LIB_FUNC Hello
{
    private:
        const char * who;
    public:
        Hello(const char * who);
        void sayHello(unsigned n = 1);
};
我的头文件如下所示:-

src/main/cpp/HelloWorld.cpp
src/main/headers/HelloWorld.h
// Hello.h

#if defined(_WIN32) && defined(DLL_EXPORT)
#define LIB_FUNC __declspec(dllexport)
#else
#define LIB_FUNC
#endif

class LIB_FUNC Hello
{
    private:
        const char * who;
    public:
        Hello(const char * who);
        void sayHello(unsigned n = 1);
};
我的资料来源如下:-

// main.cpp
#include "Hello.h"
int main(int argc, char ** argv)
{
    Hello hello ("Pepito");
    hello.sayHello(10);
    return 0;
}
当我尝试运行gradle InstallMain可执行文件时,出现以下错误:-

HelloWorld.obj : error LNK2019: unresolved external symbol "public: __thiscall Hello::Hello(char const *)" (??0Hello@@QAE@PBD@Z) referenced in function _main
HelloWorld.obj : error LNK2019: unresolved external symbol "public: void __thiscall Hello::sayHello(unsigned int)" (?sayHello@Hello@@QAEXI@Z) referenced in function _main
我使用的是visual studio 2012以及它附带的任何cl.exe。我让我的朋友在OSx中用clang++进行编译,结果他成功了。我不知道怎么了。有人能帮忙吗

我的gradle版本:-

------------------------------------------------------------
Gradle 2.4
------------------------------------------------------------

Build time:   2015-05-05 08:09:24 UTC
Build number: none
Revision:     5c9c3bc20ca1c281ac7972643f1e2d190f2c943c

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.4 compiled on April 29 2014
JVM:          1.8.0_45 (Oracle Corporation 25.45-b02)
OS:           Windows 7 6.1 amd64

我终于成功了

DLL_导出符号的定义应按以下方式以渐变方式进行:-

binaries.withType(NativeLibrarySpec) {
    if (toolChain in VisualCpp) {
         cCompiler.args "/Zi"
         cCompiler.define "DLL_EXPORT"
    }
}
这将确保VisualStudio拾取正确的导出符号。默认情况下,所有符号都在g++和clang++中导出,因此不会造成太多问题。但您必须添加此项才能断言符号是在链接阶段导出的

多亏了。每个人都应该仔细阅读这份文件