C
C#2mo ago
MrScautHD

Compile Native Lib

I wanna ask how i can build a C project in my .csproj to use the .dll from it, do someone know or has a example for me?
27 Replies
Jimmacle
Jimmacle2mo ago
you could set up your C# project to run your C compiler on build then the usual pinvoke from there
Jimmacle
Jimmacle2mo ago
Exec Task - MSBuild
Learn to use the MSBuild Exec task to run a specified program or command by using the specified arguments.
MrScautHD
MrScautHD2mo ago
i never done something like that before, do you maybe have a example for me? thx, but do you have some examples?
Jimmacle
Jimmacle2mo ago
yeah, on that page i haven't done exactly what you want for any projects, this is the general solution to running an arbitrary program as part of a C# build see https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-targets?view=vs-2022 as well
MrScautHD
MrScautHD2mo ago
this tell me just to run a command
No description
Jimmacle
Jimmacle2mo ago
yeah that's what it's for the command will depend on how your C project is set up and what build system you're using for that
MrScautHD
MrScautHD2mo ago
CMake
Jimmacle
Jimmacle2mo ago
so you'd run whatever command you need to make cmake build it
MrScautHD
MrScautHD2mo ago
btw would it possible to automatically download the C lib?
Jimmacle
Jimmacle2mo ago
download from where?
MrScautHD
MrScautHD2mo ago
from .csproj
Jimmacle
Jimmacle2mo ago
no like where is the C lib?
MrScautHD
MrScautHD2mo ago
Github tags
Jimmacle
Jimmacle2mo ago
i mean you could probably do that with msbuild too if you wanted to
MrScautHD
MrScautHD2mo ago
do you know how?
Jimmacle
Jimmacle2mo ago
yes, by looking at the msbuild docs about targets that i linked earlier
MrScautHD
MrScautHD2mo ago
kk
Jimmacle
Jimmacle2mo ago
why do you need to both download the library and build it from source?
MrScautHD
MrScautHD2mo ago
yea i want to download it and build it
Jimmacle
Jimmacle2mo ago
?
MrScautHD
MrScautHD2mo ago
then i just need to write the new version of the program like <ReleaseTag>5.0<ReleaseTag> i doing a wrapper to c#
Jimmacle
Jimmacle2mo ago
you wouldn't want to do that with msbuild, you'd add the repo as a submodule or something
MrScautHD
MrScautHD2mo ago
well then i wanna do that
Jimmacle
Jimmacle2mo ago
if you're writing a wrapper why are you concerned with building the native lib in the first place? you don't need to do that to build your wrapper
MrScautHD
MrScautHD2mo ago
? i mean i need the .dll for any platform
Jimmacle
Jimmacle2mo ago
yeah but why is that a concern of your project you haven't really explained what the native lib is or why you need to build it this way
MrScautHD
MrScautHD2mo ago
i would just like too create it like that but a submodule is no bad idea too and then compile it by runing the cmake command