There are three projects:
project A (my project, WPF .NET 4.5)
project B (managed C++ with CLR (.NET wrapper for the FANN library))
project C (unmanaged project made in C, (FANN library))
In Visual Studio 2012 with project A opened, I can't step into to the project C through the project B.
Project B and C are free and open source and I have already built them successfully.
Project A references project B's DLL and project A won't run if the project C's DLL file cannot be found - so I have copied and pasted the DLL for the project C inside the project and set "Copy always" to the output directory.
When stepping into during debugging, I can get only to the project B's source code. I don't even see the project C loaded in the Modules window which I do not understand at all.
The project wouldn't run without the project C's DLL included and when it's included, it won't load but all the calls are working so it must be loaded somewhere.
I tried to include the project C's PDB file to the project A's output directory but no luck, function calls from project B to project C still get stepped over and never into.
Note that:
Just My Code is disabled
project C is included in the project B's in two ways - a "lib" file (in the linker settings) and its ".h" files in the source code are referenced... I don't know if that is the problem but you might.
I know there must be a way to achieve this, I have all the source code available but I'm no expert in C or C++ code, nor in debugging of it. I have tried including all the various project C's files from the bin directory to the project A but can't get it working.
Thanks for any help or advice!
If you're using Visual Studio, you have to explicitly enable debugging unmanaged code. You can do this from
Solution Explorer -> csproj -> Properties -> Debug -> Enable unmanaged code debugging
Related
I have been successfully testing an image processing library (https://github.com/libvips/libvips) in a C++ project in VS2017. I am new to C/C++ and I have been following the documentation here which describes the C way of using the library. There are features I would like to try in the C++ API, but the C++ API needs to be built with the same compiler as my project. According to the author:
It's slightly awkward to set up under Windows. The problem is that C++
does not have a ABI, so you must use exactly the same C++ compiler for
your whole project. This means the libvips C++ win binary (built with
g++) won't work with MSVC C++.
You need to copy the libvips C++ API source code into your own project
and build it with your own code. It's just a few files and pretty
simple to incorporate:
https://github.com/libvips/libvips/tree/master/cplusplus
I have made several attempts to build the minimal set of files but I have not had any success.
My steps so far:
Create a C++ console app in VS2017, set to Debug and x64
Extract the 'vips-dev-8.10' folder from vips-dev-w64-all-8.10.6.zip to where the project file is (this contains all the built .dll files, .lib files, .h files etc.)
Extract 'cplusplus' folder from 'libvips-master.zip' to where the project file is (this has all the project source files including the cplusplus folder which is the part I have to build per the above explanation)
Add the following folders to Project > Properties > C/C++->General > Additional Include Directories
C:\Projects\ConsoleApplicationVIPS3\ConsoleApplicationVIPS3\cplusplus\include\vips
C:\Projects\ConsoleApplicationVIPS3\ConsoleApplicationVIPS3\vips-dev-8.10\include
C:\Projects\ConsoleApplicationVIPS\ConsoleApplicationVIPS\vips-dev-8.10\lib\glib-2.0\include
C:\Projects\ConsoleApplicationVIPS\ConsoleApplicationVIPS\vips-dev-8.10\include\glib-2.0
Add the 5 .cpp files from the cplusplus folder into the project Source Files folder and Add them in the project tree.
Build the project.
As a result I get the following errors:
I haven't written any code yet. I thought I should just be able to point to the .h include files and compile the required C++ files. It's not clear to me what else I might need to add, but it definitely seems like I don't understand the correct procedure to build the project. I watched some videos on C++ compilation like this one but I cant see where I went wrong.
Any thoughts would be much appreciated.
EDITS 3-Jun-21
I have made some changes. I have instead extracted the exact version of the library according to the suggestion by #Frank, and I also discovered the usefulness of the compiler output window, thanks #Alan Birtles.
I am still getting errors, but I am not clear why. The first error is:
E0020 identifier "VImage" is undefined
Which is odd because I have added the folders to Project > Properties > C/C++->General > Additional Include Directories, and one of them is ..\cplusplus\include\vips which contains VImage8.h
And the Output window shows
Any further advice would be appreciated!
My goal is to compile existing C++ classes (legacy code, stored in a set of *.h files) into a DLL so that it can be further integrated into a C# application.
For that purpose, it seems best to use MS Visual Studio. I have no experience with this environment, so I tried the naive approach found on MSDN and other SO answers:
File | New | Project from existing code
selected Visual C++
selected file location that is base for include references used in those .h files
specified a project name
let the wizard find and add all C++ files below the directory
selected "Use Visual Studio" for build, with project type "Dynamically Linked Library (DLL) project"
checked none of the checkboxes below (ATL, MFC, CLR)
specified . dir in the "Include search paths (/I)" in Debug settings
checked "Same as Debug configuration" in "Release settings"
clicked Finish button
This creates couple of VS files in the directory:
mylibrary.sln
mylibrary.vcxproj
mylibrary.vcxproj.filters
mylibrary.vcxproj.user
With a project created this way, I press F6 or select Build | Rebuild solution from the menu.
Then I expect the build to produce the .dll file somewhere, but it does not appear. Only these files appear:
.vs/mylibrary/v15/.suo
.vs/mylibrary/v15/Browse.VC.db
.vs/mylibrary/v15/Browse.VC.opendb
.vs/mylibrary/v15/ipch/AutoPCH/efad7c74cd39331b/EXAMPLE.ipch
Debug/mylibrary.log
Debug/mylibrary.tlog/mylibrary.lastbuildstate
Next, I decided to try creating a fresh new library project, just to observe the differences to get some hints, but that did not help - there were too many differences, even in the file structure...
My questions are:
is my choice of MS Visual C++ a good one for given purpose?
if so, what am I doing wrong here?
I think your steps are probably correct and I think that the right approach to use the code from a C# application. You definitely can call a C++ library from C# by importing the methods.
You missed only to export the methods that you want to use from your library. try using __declspec(dllexport) with these methods. please check this link:
https://msdn.microsoft.com/en-us/library/a90k134d.aspx.
Also, the output should be at the build folder, not the source code folder
Compiling .h files into libraries is ok, the compiler does not care - however, the UI does.
Still, you can tweak this by directly editing the .vcxproj file.
While doing so, make sure that the <ClCompile> sections contain:
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
Note that you can use commandline for building the DLL project:
"%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" -target:Clean,Build
(this assumes that your current directory is the one with your .vcxproj)
Background: In visual studio 2015, I have an project A built as an application. I want to create two packages B and C which wrap the contents of A into a DLL (in B) and into a runable application in C. After removing the main from A, I want to change project A from an application to a static library.
I tried changing the
Project Properties|Configuration Properties|General|Project Defaults
from Application (.exe) to Static Library (.lib). This leads to a linker error:
LINK : fatal error LNK1561: entry point must be defined
Obviously, Visual Studio still thinks that this subproject has to be compiled like an application (see here ). It therefore expects that there is a int main() which I don't want to have anymore.
So, how can I change the project type so that it is compiled as a static library?
There seems to be no way to change the build type from the GUI.
However, this can be done by altering the file A.vcxproj.
Search for all tags <ConfigurationType> and change them from Application (or whatever you have there) to StaticLibrary.
This only needs to be done for project A - the solution will adapt, the next time you start it in Visual Studio.
To properly link A into B and C, don't forget to:
1) Add a reference from B and C to A.
Open Solution>Project B/C>References, choose Add Reference, add reference to A.
2) Add a project dependency from B and C to A.
Open the context menu for any project and select Build Dependencies...>Project Dependencies>Dependencies. Add A as a dependency for both B and C.
In Visual Studio 2017, you can change the Configuration Type using the Project Properties.
With your project open, go Project / Properties.
Under Configuration Properties / General / Project Defaults, there is an entry called Configuration Type. The choices I see are Static Lib (.lib), Dynamic Lib (.dll), Application (.exe), Makefile and Utility.
My project was imported as a Dynamic Lib. I updated this setting and it now generates Static Lib. Related to the other answer, changes this setting in Visual Studio did result in the value within the project.vcxproj file to be updated. I figure doing it through Visual Studio instead of directly on the file would be more safe.
I am using visual studio 2010.
Problem:
I want to build project A, B and C. Project A and B are independent where C will use both of them as a library. I open three empty c++ projects. I build and compile project A and B with no errors.
Then I build project C with adding the exiting project function, adding additional include directories through Project->Property->C/C++->General->Additional Include Directories.
After that, I finished building project C and then compile, following is the error I got.
Error:
LNK2019, LNK1120
I searched through the web and I belief that there should be some additional setting is need under the Project->Property->Linker...
But I am not sure what they are, anyone can help?
I have a cpp which depends on couple of headers in the same folder. I need to compile this cpp to a dll. How do I do it in visual studio 2010 expresS?
I found few articles on web for visual studio 2008 but I could not use it in 2010. Any pointers would be highly appreciated. Btw, I am a java programmer. CPP is all new to me, I am compiling some one else's cpp to dll.
Thanks,
Abi
Right-click on your project in the Solution Explorer, and select Properties.... Under Configuration Properties -> General there's an option called Configuration Type. If you change it to Dynamic Library (.dll), your project will generate a DLL when it is built.
As a start point, you can use "Create New Project from Existing Code" as described here - specify that you want a DLL project when prompted.
Once you have a project in place that encapsulates your CPP code file, you can find other info on specific project settings in MSDN, or post new questions as you need to.