cpp_gradle icon indicating copy to clipboard operation
cpp_gradle copied to clipboard

Head scratcher - where's the .lib?

Open dlaio opened this issue 9 years ago • 2 comments

The windows build doesnt end up outputting a .lib file in the /build/binaries/helloSharedLibrary/ directory, so the executable isnt able to link to it (therefore fails).

The library is in the static folder, copying it to the shared directory will make it work, but I dont think that is the intent. Oddly, the samples in the gradle release produce a .lib file in the shared folder, and as far as I can tell, the gradle.build file is the same.

Any ideas what is going on? Why isnt there a .lib file in the shared folder for this project? Just trying to wrap my head around what the gradle native plugin is doing. My first thought is that the link step should actually be looking for the .lib in the "static" folder, not the shared folder, but I dont know enough about the domain to know if this is a bug.

dlaio avatar Dec 04 '15 15:12 dlaio

During linking with Visual Studio, if there is no symbol to be exported, then the .lib file will not be created. Append the following in build.gradle:

model {
    binaries {
        withType(SharedLibraryBinarySpec) {
            if (toolChain in VisualCpp) {
                cppCompiler.define "DLL_EXPORT"
            }
        }
    }
}

And change at least the interface of the class Hello to:

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

class Hello 
{
    private:
        const char * who;

    public:
        LIB_FUNC Hello(const char * who);

        void LIB_FUNC sayHello(unsigned n = 1);

};

Araeos avatar Apr 10 '16 12:04 Araeos

@Araeos thanks for the reply, I can't test it.

@dlaio , can you please test the solution proposed by @Araeos? If it is OK, can you please close the issue?

carlosvin avatar May 16 '16 13:05 carlosvin