开发者

Calling C++ LINK from a csproj in VS2008

开发者 https://www.devze.com 2023-04-12 16:29 出处:网络
I\'m interested in combining a single .cpp file (containing both native and managed code) into a larger C# project.I don\'t want to use a separate DLL for the CPP code, both because it seems silly to

I'm interested in combining a single .cpp file (containing both native and managed code) into a larger C# project. I don't want to use a separate DLL for the CPP code, both because it seems silly to "waste" a whole DLL for just a few lines of code, and because the code has some security functionality which I would prefer to obfuscate a bit by hiding it within a larger assembly. (And before someone suggests it, I can't use ILmerge or AL because they don't work for native code.)

The basic process of compiling a .cpp and group of .cs files has been covered a few times; the leading candidate suggestions seem to be:

  • http://blogs.msdn.com/b/junfeng/archive/2006/05/20/599434.aspx
  • http://blogs.msdn.com/b/texblog/archive/2007/04/05/linking-native-c-into-c-applications.aspx

However both of these (and all related links I could find) only deal with building on the command line.

I would prefer to alter my existing .csproj file to compile and link in the C++ code (I don't mind the C++ build itself being in a separate .vcproj, although better if not, but the link has to be in the .csproj), and have it all be buildable from within VS2008, so that users of the project don't need to know the difference.

Unfortunately, I can't seem to successfully call link.exe from within a .csproj being compiled by VS. An "Exec" element with "link" can't find the executable, because it's not in the PATH. Specifying the location explicitly ("$(DevEnvDir)....\VC\bin\link") does start to run it but it immediately fails with an error code indicating that it can't load libraries it needs (presumably because again, it's not in the PATH).

Are there any examples of successful calls to LINK from a csproj from within Visual Studio?


Edit: ok, I've managed to work around that issue now, and everything is compiling, linking, and running fine -- in release mode. It still s开发者_如何学JAVAeems to run ok in debug mode, but for some reason its SxS manifest (which LINK generates but I had to apply manually via mt) only refers to the release CRT, not the DebugCRT. Any ideas how to fix that?


When you link using obj and lib files built using the Debug configuration, it should reference DebugCRT.

What does your command line look like?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号