Making a GCC based Project Build and Run under Visual Studio 2010 - c++

I have been trying to port my C++ based mass data transport protocol project into visual studio 2010 with no success :(
The code I have been working on is fully compatible with Win based systems..well this is what my mentor also says :) But I have not been able to make the project build and run using my existing *.h & *.cpp files under VS 2010.
The Project basically is a API under which i have 4 separate applications. The hierarchy would be:
SRC FOLDER- all the *.h and respective *.cpp files
APP FOLDER- 4 applications (the API / library and some *.h files to be available before linking such as the final dll file under SRC folder & the main header file under APP folder)
I do also have a makefile as when the project was developed on Linux platform but I have no idea how to implement the same on Visual Studio 2010
FYI: VS 2010 on compiling reports that there are missing header files such as <cstdlib>, <unistd> but my best bet is this is not the real prob. but the prob. lies in the way I make the project build itself. I don't know should I go with making a dynamic dll project for the main library and then make the 4 empty c++ projects inside that for the 4 respective applications..?
Cheers,
echo9

I would recommend that you parse the data that you need from the working .mak file that you used previously. Create an empty project & sln, then add the contents of the "src" by using "add->existing files" in the file menu.
At that point open up the project configuration settings and go through the C++ and linker settings one by one. At each step have a look at the linux .mak file and see that you are choosing equivalent options and path settings. In particular make sure that you add all of the necessary include paths to where your .h files are.
That's what I would do anyways... same process as porting forwards old MSVC4 .mak projects to a modern version.

Related

Building C++ API of Third Party Library in Visual Studio C++ Project

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!

External C++ source files in android studio?

Here is the drill. I have a cross-platform project written mostly in C++ (more on this later) that runs on windows, android and ios.
Is there any way in which android studio can be configured to have a custom directory that contains all the native C++ code ? By custom, I mean external to the main folder in which the android studio project resides in.
I'm guessing you can see where I'm getting at... I have a cross-platform project that can be opened from 3 different IDE's... visual studio, android studio and xcode and I want to be able to write / edit / compile the code from all of them.
Let's say I have the following main hierarchy:
projectDir
src (C++ source files .cpp)
include (C++ headers .h)
_visualStudio (visual studio project)
_xcode (xcode project)
_androidStudio (android studio project)
assets (resources .png etc)
others...
This is what I want to achieve, but I am unable to figure out how can I configure an android studio project to be able to accept external source files, but most importantly to be able to see and edit them from the android studio IDE. Basically I want to tell android studio... "Look, this is the path for the native files, treat them as if they belong to the project".
I know this is possible from visual studio and from xcode because I already did that, but up until now I used my own build system for android and I had no need for android studio. Is there any way to achieve this ? Perhaps some kind of symbolic folder links ?
The thing is I want to keep only a single copy of my shared resources (src, include and assets should only be in one place, but should be available for android studio as well).
So far the only solution is to keep them inside android studio project directory, and change visual studio paths to look for them there, but I find this very nonprofessional.
EDIT:
Is there any addFileToProject (as in visual studio) in android studio in which the file can be outside the project ?
After a bit of more digging I found that it is actually possible.
You just have to create a directory junction like this (inside app/src/main/cpp where the files would normally be).
mklink \J linkName linkDestination(can be outside the project)
Android studio will be able to see the containing folder as it's own (it sees it as a link, but you can double click it to expand the contents). You can also edit source files inside it with the only mention that you have to add these files within CMakeLists.txt or whatever build file you are using in order to have intellisense (you get a sync warning from android studio if the files aren't referenced anywhere in the build files).
Later edit... if you are using junctions for Java / Kotlin files in an android studio project, make sure to set the source sets through the junctions as well... in order to avoid visual errors like 'duplicated class'.

Create MS Visual C++ DLL project out of existing sources

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)

Build C++ Projects with Makefile using Visual Studio 2008

I downloaded cpptest from internet, and I want to build it using Visual Studio 2008.
The problem is that instead of .sln and vcproj file, Makefile.am is distributed, and I believe that all the all the necessary included file is included in the Makefile.am.
How to use Makefile.am to generate VS project files? I tried to use Cmake, but there is no CMakeList in the distribution.
Edit: Thanks to all the answers! There is a sln file distributed after all. But I am still interested to know the answer to my original question.
the visual studio project files for cpptest are in the win directory, not in the src directory where the makefile is..
edit
makefiles are meant to be used with GNU make. If you want that on windows, you can look at Mingw, GnuWin32 or Cygwin. But they also require gcc for compiling, so you won't really be using VS.
However, for most projects that do not have external dependencies it's no big deal if you do not have the VS project file: after all a makefile is just a list of the source files and some compilation options. To successfully build projects like cpptest, you could just create an emtpy VS project, add all source files to it, set output type to executable, build it and you're done. Eventually you can tune optimization options, but for the rest the default options will just do fine.
Go to win\VisualStudio.NET and you will find a VS solution file.
I just downloaded the archive and found the .sln file. It is under: /win/VisualStudio.NET. You can open that with VS2008 and update it, it should work.

Cross-platform svn management (Makefiles & Visual Studio)

I'm working on a little game called freegemas, it's an open source version of the classic Bejeweled written in C++ and using gosu as the graphic API. I've been developing it under Ubuntu Linux as usual, but the other day I wanted to give it a try and I compiled it on Windows using Visual Studio 2005 (which I had never used before). The program worked flawlessly.
To compile it on Windows I manually copied all the source and header files to a new project on MSVC, but I would like to adapt the SVN so I don't have to recreate the project every time I want to compile it.
Therefore, the question would be: What's the best way of organizing the svn so I can have, on the one hand, a Makefile to compile the project in Linux, and, on the other side, the MSVC project's files? Right now I've got a simple folder called trunk with all header, source and resource files on it.
I've never used Visual Studio before, so I don't know which files are the most important either. Maybe some of those files are auto-generated and do not need to be svn-versioned.
Thanks in advance.
You could just keep the project files in a seperate directory "winbuild" or similar. Still, to maintain them would require manual interaction (ie adding every new file manually). The only files you would need to upload to svn are the *.vcproj (for MSVC 2005/2008) and *.vcxproj (MSVC 2010).
Alternatively, you could opt for a cross-platform solution like CMake, which could generate makefiles and Visual Studio project files from a common CMakeLists.txt, which is the only "project file" that would have to be maintained (instead of your makefile). Especially for a simple (?) project like yours (some headers+sources). There would be no need to include any makefiles or vcproj files at all, just the CMakelists.txt file would suffice.
There are others like CMake (SCons, boost.jam, jam, premake, etc.)
It should be feasable, but requires some testing and trial-and-error.