I am building a project in C# to interface with a C++ library. Because I want this to be cross platform I am using .NET Core RC3 though I'm not sure if that is relevant.
Right now I have the cpp files in my project and I have a PreBuildEvent
like
<PreBuildEvent>
gcc -c -fPIC -std=c++11 "$(SolutionDir)ProjectName\cfile.cpp" -o"$(SolutionDir)ProjectName\cfile.o"
gcc -shared -o "$(SolutionDir)ProjectName\cfile.dll" "$(SolutionDir)ProjectName\cfile.o" -lstdc++
</PreBuildEvent>
The DLL gets built, and then copied to the output directory. Then I use PInvoke to communicate with it.
This part works. Then I add a test project that references the first project. The part that doesn't work is when I try to do dotnet test
.
Then it says
gcc : error : ProjectName\cfile.cpp: No such file or directory
I guess $(SolutionDir)
must not be set in this case, or something.
If I change the project to a command line application, and do dotnet run
that doesn't work either.
$(ProjectDir)
doesn't seem to be available in this case either in the PreBuildEvent
or the PostBuildEvent
.
What's the best way to set this up so it works?