Windows form application using Visual Studio c++, that links to a CUDA project - c++

I am trying to implement a Windows Form Application using Visual Studio C++ that links to a CUDA project.
I created WFA.
Then I try to dynamically link the application to CUDA project by browsing the .dll in the Add Reference part of the Project Properties. But it said "Could not add ... it is not a .NET assembly or registered ActiveX control".
Thus I add the .obj of the CUDA project to the Linker->Input->Additional Dependencies part with the .lib files that are required to run CUDA in WFA project. Then I got "fatal error LNK1313: pure module detected; cannot link with ijw/native modules" error.
I changed the Common Language Runtime Support from "Pure MSIL Common Language..." to "Common Language..." but then msvcrtd.lib and libcmt.lib is conflicted. This error disappears when the .obj files of CUDA project are deleted from the "Additional Dependencies".
Since CUDA project's runtime is MT and WFA project's is MT dll, this error occurs. I changed the runtime of WFA to MT, but then "error D8016 : '/MTd' and '/clr' command-line options are incompatible" error occurs.
Since /clr is required for "System::" being recognized, I cannot get rid of the /clr option.
Do you have any suggestion to create a windows form application using Windows c++ that links to a cuda project in the easiest way? Or if there are easier way I would be glad to hear them.

I think your WFA app is a managed C++ .NET application using CLR. You are trying to include the unmanaged CUDA DLL as if it were a CLR Assembly or a COM Object. Thus VS is saying /MT (use unmanaged Multi-Threaded C run-time) and /CLR is not compatible.
So you need to either wrap the CUDA DLL in CLR object or use a .NET Binding for CUDA in your project. Try downloading CUDA.NET and incorporate that into you project as reference.
http://www.hoopoe-cloud.com/Solutions/CUDA.NET/

Related

Building a static lib without C/C++ runtime in Visual Studio

Is there a way to build a static library without specifying the version of C/C++ runtime?
I'm using Visual Studio 2017 to build a static lib, and I have to specify a version for "Runtime Library" in the "Code Generation" option page (\MD or \MT). If I choose one version and the application using my lib chooses another, Visual Studio will spit out the error: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease'.
I know, when building an EXE, I can use the linker switch \NODEFAULTLIB to not include C/C++ runtime, but I'm building a static lib here which doesn't even have the Linker option page in its Properties window.
It seems that Simple DirectMedia Layer found a way to do.
Update: I later realized that I could actually turn on \NODEFAULTLIB switch in the Librarian option page in the static lib's Properties window.
You do it by NOT using any Runtime libraries. If you don't use any of the runtime libraries then the "Code Generation" option is meaningless as the runtime stubs are not pulled into obj file.
SDL basically say this on there web site:
On Windows, SDL does not depend on a C runtime at all, not even for
malloc().
As soon as you use any system include supplied by Microsoft VS then you are using there runtime library.
So if you only use the Windows SDK and the API supplied by the Win32 API then you don't need the VC runtime.
If you build a static library, it refers to your own library and not to the application as a whole. If you want to distribute the application, it just means that you will not need to distribute a separate dll. So do not set NODEFAULTLIB.
If you run the application on a machine where there is no Visual Studio 2017 installed, you might get an error message. The missing dlls are system libraries that are needed to run vs applications that are compiled with VS2017. You can get the missing libraries from: https://support.microsoft.com/en-gb/help/2977003/the-latest-supported-visual-c-downloads (this link is not guaranteed to be correct in the future). The redistributable dlls can be distributed freely. They are called vc_redist.x86.exe and vc_redist.x64.exe. Choose vc_redist.x86.exe if you have compiled you code for 32-bits. It does not refer to the machine on which the app is run.

error MSB8024: Using static version of the C++ runtime library is not supported

I created simple Windows Runtime Component using Visual Studio template. By default project is dynamically linked to C/C++ Runtime Library with MD/MDd option.
When I change it into MT/MTd (Project properties -> C/C++ -> Code Generation -> Runtime Library) and build the project I am getting error
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppBuild.targets(1693,5): error MSB8024: Using static version of the C++ runtime library is not supported.
How can I compile Windows Runtime Component with MTd option?
I need this since WinRT Component will refer other 3rd part library which is built with statically linked C++ runtime library.
Unfortunately you can't avoid the restriction.
But I have doubts about "I need this since WinRT Component will refer other 3rd part library which is built with statically linked C++ runtime library". Did you try to use that 3rd part library? You should have no problems adding it to your project.

Compiling V8 on Windows to Use with g++

I have gone through all the procedures on how to compile V8 and actually managed to compile it on Windows platform. However, the problem is that the compilation procedure on Windows forces you to compile with Visual Studio and therefore creates object files (.obj) which can be used in VS. I have managed to create a DLL file too but it only serves the purpose when there is an executable to run.
On the other hand, I am using Eclipse and g++ on Windows. To embed V8 into my C++ I will need to have a library file (.a extension so that the linker will work). Is there a way that this is doable?
When the DLL was created an import library should have been created as well. They typically have the same name as the DLL but with a .lib extension. Add this library to your project in Eclipse and it should be linked in at build time. you can do this by right clicking on the project and selecting Properties -> C/C++ Build then go Library and add it there.

How do I install Crypto++ in Visual Studio 2010?

I downloaded http://www.cryptopp.com/#download 5.6.1 and have no clue that to do at this point. I am a total noob and need good instructions. thanks.
Directly from the readme (Which can be found here Crypto++ Svn Trunk):
* MSVC-Specific Information *
On Windows, Crypto++ can be compiled into 3 forms: a static library including all algorithms, a DLL with only FIPS Approved algorithms, and a static library with only algorithms not in the DLL. (FIPS Approved means Approved according to the FIPS 140-2 standard.) The DLL may be used by itself, or it may be used together with the second form of the static library. MSVC project files are included to build all three forms, and sample applications using each of the three forms are also included.
To compile Crypto++ with MSVC, open the "cryptest.dsw" (for MSVC 6 and MSVC .NET 2003) or "cryptest.sln" (for MSVC 2005 - 2010) workspace file and build one or more of the following projects:
cryptopp - This builds the DLL. Please note that if you wish to use Crypto++ as a FIPS validated module, you must use a pre-built DLL that has undergone the FIPS validation process instead of building your own.
dlltest - This builds a sample application that only uses the DLL.
cryptest Non-DLL-Import Configuration - This builds the full static library along with a full test driver.
cryptest DLL-Import Configuration - This builds a static library containing only algorithms not in the DLL, along with a full test driver that uses both the DLL and the static library.
To use the Crypto++ DLL in your application, #include "dll.h" before including any other Crypto++ header files, and place the DLL in the same directory as your .exe file. dll.h includes the line #pragma comment(lib, "cryptopp") so you don't have to explicitly list the import library in your project settings.
To use a static library form of Crypto++, make the "cryptlib" project a dependency of your application project, or specify it as an additional library to link with in your project settings. In either case you should check the compiler options to make sure that the library and your application are using the same C++
run-time libraries and calling conventions.
If you have any questions feel free to ask and i'll update the anwser with my responses.
I downloaded http://www.cryptopp.com/#download 5.6.1 and have no clue what to do at this point...
This is a very late answer, but the project has released some new files to help folks use Visual Studio 2010 and above.
The project had to release the updated files because VCUpgrade (provided with Visual Studio 2010) does a fairly poor job with this particular project. It has been a source of problems for a few years, and even visually impaired users were commenting about it. The problems were not fixed in VS2012, VS2013 and VS2015, so we don't believe Microsoft has any intentions of fixing the problems.
To use the updated files, download the latest Crypto++ release from the website. Then, visit the Crypto++ wiki and fetch vs2010.zip from the page Visual Studio. Unzip vs2010.zip over the Crypto++ files. Finally double-click the file called cryptest.sln to have Visual Studio open the solution file.
The Crypto++ wiki page also offers project files that provide dynamic runtime linking for both VS2005 and VS2010.
If you convert cryptest.sln from VS2005 to VS2010, you will meet a problem. When you compile source code, the compiler will show an error:
c1xx : fatal error C1027: Inconsistent values for /Ym between creation and use of precompiled header
You can resolve this problem by:
Going to Project Properties --> Configuration Properties --> C/C++ --> Precompiled Headers
Changing it to "Not Using Precompiled Headers"
You'll need to compile the library before using it with anything. You can't just install it. Here is a page from their wiki about compiling the library: http://www.cryptopp.com/wiki/Compiling

A C++ Application Compiled With VS2008 Doesn't Run In Other Computer

I have created a wn32 project with Visual Studio 2008 and Visual C++ language, it uses the ws2_32.lib library and then I compiled in Release mode.
It runs very good in the same computer, but when I copy the exe file to other computer (that doesn't have installed Visual Studio), it doesn't run.
The message I see is:
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
But, if I compile my application using DEV C++, it generates a bigger executable (738KB) compared with the Visual Studio 2008 executable (9.5 KB). However, the DEV C++ executable runs in the other computer.
I have add the library ws2_32.lib to the linker properties of my project, in the Additional Dependencies field.
How can I fix it to work with Visual Studio 2008?
My code is the following: http://www.stan.com.mx/yupi/udpserver.cpp
The problem is almost certainly that the other computer does not have version 9 of the C++ CRT installed.
The default setting for compiling against the CRT in VS2008 is to dynamically link vs. statically linking. If you want to deploy your program with a real setup project you'll need to include the CRT redistributable.
However if you want to do an XCOPY deployment follow the steps on the following page.
http://msdn.microsoft.com/en-us/library/ms235291.aspx
Try installing the Visual C++ redistributables. If that doesn't work, use DependencyWalker to find out what DLLs are missing.
I agree with JaredPar. The application you build with VS2008 is using dynamic linking, whereas the DEV C++ is linking statically, hence the larger size and why one works and not the other.
However, if its a plain win32 application project you've got (and you don't want/need to distribute it with a setup), you may be able to get it to run on another machine without redistributing the CRT by getting VS2008 to link statically for you (if its just the standard lib you're missing). I don't have a copy of VS2008 to hand, so I'll describe how to do it in VS2005 and hopefully it'll translate across.
Bring up configuration properties for the project (right click the project name, then select "properties" from the menu)
Expand "Configuration Properties", then "C/C++", then click "Code Generation"
Under the "Runtime Library" item, for your particular configuration select the non-DLL version of the library i.e. for debug builds you want "Multi-threaded Debug (/MTd) and for release builds you want "Multi-threaded (/MT)"
Try and see if that works. You'll obviously get a much bigger final binary now the library is statically linked.
You may be missing an external dependency required by your program. Check the project settings to see if you are linking against MFC dynamically for example. You can also run Depends utility to check for missing dependencies.