Porting several dependent C++ makefile projects into MSVC - c++

I have several projects which depend on each other. For example, when I install them I do this:
Project1:
/configure & make & make install
Project2:
/configure & make & make install
Such that "Project2" depends on some libraries of "Project1". I want to create an MSVC project for Project2, and start working with it, and changing it (and compiling it inside). How can I do this?
Also, how different is this to be done in linux with Eclips (when you don't have admin permission and can't do 'make install')?

You can create project dependence in Visual Studio.
To assign dependencies to projects
In Solution Explorer, select a project.
On the Project menu, choose Project Dependencies.
The Project Dependencies dialog box opens.
On the Dependencies tab, select a project from the Project drop-down
menu.
In the Depends on field, select the check box of any other project
that must build before this project does.
You can read more about it here

Visual Studio is your usual clickfest, but you can define project dependencies.
Define one project per module, then go to the solution properties tab and, for each project, select the checkboxes that inform the IDE that this project depends on a set of other projects.
The IDE will then sort and build them in the appropriate order.

Related

Specifying external Makefile options in Eclipse CDT

I'd like to (temporarily) migrate a C++ project from Netbeans to Eclipse (in order to use Eclipse's parallel debugger). So far I've created a "Makefile project with Existing Code" project in Eclipse that references the Netbeans project Makefile/directory. However the Netbeans project accepts config options for example
make -f Makefile CONF=GNU_Debug
How can I pass this option to the Makefile in Eclipse?
Eclipse version
Eclipse for Parallel Application Developers -- Mars.2 Release (4.5.2)
You can change the default make call in the projects properties dialog:
My version:
Version: Mars.1 Release (4.5.1)
Note that the -f Makefile should be superfluous.
In addition to πάντα ῥεῖ's answer, which changes settings "globally" for a project, you can define individual make targets in the Make Target view.
Steps:
Choose Window -> Show View -> Other... -> Make -> Make Target (or simpler, press Ctrl+3 then type Make Target and choose the view from the list.)
Right click on the project in the view and choose New...
Enter the make target you want to use, e.g. CONF=GNU_Debug and press OK
Double-click on target to build
Here is a screenshot:
Shortcuts
You can quickly rebuild last selected Make target by pressing F9
Bring up a pop-up to select Make target by pressing Shift+F9
Access the same UI as above by right-clicking on project in Project Explorer and choosing Make Targets -> Build or selecting the same from the Project menu.

Multiple build targets in visual studio C/C++

Is it possible to compile in one fell swoop multiple build targets? For example, I would like to compile an .exe and a static library which includes everything but the .c file that includes main()
If that's not possible, how to manage multiple build targets like this?
You actually can build multiple configurations of the same project. So you need make sure each individual configuration builds okay and in separate path. Then you can use Batch Build dialog to do build all in one time. I hope it should be even possible to build exe and dll using the same project, but different configurations.
Build multiple configurations simulataneously:
On the menu bar, choose Build, Batch Build.
In the Build column, select the check boxes for the configurations in which you want to build a project.
Choose the Build or Rebuild buttons to build the project with the configurations that you specified.
For more reference, see the batch build dialog box.

Project dependency in Eclipse CDT

I'm using eclipse for the first time. I'm a seasoned VisualStudio user, so I'm trying to find similar functionality in eclipse. I have two projects, A and B. Project A spits out libA.a when it's done compiling. Project B links against libA.a. Here is my problem.
I compile project A then project B, everything is fine.
I make a code change to project A that requires a build of project A.
I try to build project B, but it states that no changes have been detected.
How do I make project B aware of the output of project A?? Currently I'm having to do a clean build of project B for it to re-link against libA.a.
Thanks.
EDIT: In my ProjectB->Path and Symbols->References tab, I have project A checked. This doesn't relink after project A is rebuilt.
Try the below settings:
Go to properties of Main Project → C/C++ General → Paths and Symbols → References
Tick all the dependencies.
You go into Project Properties of Project B, select Project References and make it reference (depend) on Project A.
Edit, appears to be a known bug
One can work around this problem by using the touch command.
In Eclipse, as part of C/C++ Build/Settings is the tab 'Build Steps'. In the pre-build steps command line, enter touch filename.
filename is any file in your application. This could be the file with main(). This could be a special file just for this workaround, touchdummy.c, which can be a tiny file, which compiles quickly.
When the application builds, even if you didn't change any sources, the touch command causes make to rebuild the application. If the library was rebuilt, then the application gets rebuilt with the new library.
One can read about how touch affects the date/time of the file here.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html
Edit: The exact command in Eclipse would be touch ${ProjDirPath}/src/main.c
Edit: This command should work, but it appears that if the 'main' project did not change, the pre-build step is not executed. Also the touch command causes eclipse to prompt to reload the file it touched. A large annoyance.
Eclipse projects depend on each other by virtue of the checkbox in the project's properties (dependent projects?) which is how Eclipse decides which to build. You can set this yourself, but it's usually set when you change your Java build path.
By default at least with QNX C++ projects, it WILL NOT check for changes in other projects.
Right click on the project, and expand "check dependencies on/off"->"check user headers only"
It seems to work, roughly...
It appears to do a makedepends on the code, and adds *.d files to the output folder which are simply depends file that list the header files.
Note: these do not appear to get regenerated, and get out of date - I do not know how to regenerate them.
For Project A (library):
Properties>C/C++ Build>Settings>Build Steps>Post-build steps> touch -m ${ProjDirPath}/source/build/build_updated.cpp
You should create folder "source/build" firstly and don't add in that folder any other files.
For Project B:
Properties>Project References> check Project A
Properties>С/С++ General>Paths and Symbols>Source Location>Link Folder>Link to folder in the file system> find and pick "source/build" folder which you created for project A before.

“Add to project list” is grayed out in Qt Project Management dialog

I'm trying to add a new statically linked library to a Qt-based application.
I used this guide: http://doc.qt.nokia.com/qtcreator-snapshot/creator-project-qmake-libraries.html
But when I get to step 4, which says "In the Add to project list, select a project. For example, myapp", I'm unable to do this because the Add to project list is disabled (gray) in the Project Management dialog.
What is required for Qt Creator to recognize other projects at this point, such that they appear in the list (which would then, presumably, no longer be disabled)?
I'm working on Linux/GNU, on a PC machine.
See the post here: http://lists.qt.nokia.com/pipermail/qt-creator/2010-December/008166.html
Your "library" project and your "application" project both need to be part of a "Subdirs" project.
First, create a Subdirs project, which will contain all the individual projects for your overall project (this is like a "Solution" in Visual Studio).
Then, create your library project, by right-clicking the "subdirs" project, and selecting "New Subproject...", and then follow the instructions from the QtCreator docs, and the overall project should be available in the drop-down.
Finally (assuming you want to create a dependency from an application to your library), create your application project as a sub-project of the overall project, and then you can add your library project as an "internal library" of your application project.

Visual Studio 2010 not autolinking static libraries from projects that are dependencies as it should be supposed to

Create a new solution with a C++ console command-line project
Create a new project, a C++ static library
Make the command-line project depend on the library
Make sure "Link Library Dependencies" is turned on in Configuration => Linker => General (it is by default)
Visual Studio will still not link the library.
How can I fix this? It worked in Visual Studio 2008.
This still works, but was changed in VS 2010:
"With VS2010, we stopped supporting project dependencies defining implicit references and we also introduced a new way of defining project dependencies at the project level. Since a project reference and a project dependency are close concepts, both applying to a project, it made sense to have them represented together, in a consistent way, in the project file. As you will see in the snippets below, the only difference between a project reference definition and a project dependency definition consists in metadata that defines the output assembly inclusion/exclusion into/from the main project link command line.
Although we did not remove the “Project Dependencies” dialog, we recommend defining new project dependencies via the “Framework and References” dialog. You need to set the “Reference Assembly Output” property in the property page UI to false for a project dependency and to true for a project reference."
Just right-click on the console project, select "Properties->Common Properties->Framework and References->Add New Reference" and add the static library project; also check that "Link Library Dependencies" is True on the right hand side. Seems to work for debug and release builds. You learn something new every day. ;)
They changed the UI for adding C++ project dependencies in VS2010, but oddly enough, without removing the old UI, or in any way indicating that it no longer works.
To create the dependency in VS2010, you need to use "Add New Reference" (can be found in project properties), and maybe also in the project's right-click menu (don't have VS here to check)
The old "Project Dependencies" dialog is basically broken now.
For MSVC 14 (2015 version) right-click on the project, then "Add->Reference..." and check all the needed dependencies.
Yes, it has changed somewhere between 2010 and 2015 versions. Fun!
And if you are looking to link a project that has resources in it - you need to specify the .res file directly in the list of linker input dependencies (project's properties dialog box) as it doesn't get picked up by the above configuration.
UPDATE
Still the same (new) behavior in MSVC 2017
I believe the old UI (dependencies) affects build order for Visual Studio, when building from within the IDE, for info. The new project configuration system embeds the references in each project file so that you can build from outside the IDE (whereas in previous versions, you could not, because you would not get automatic linking for dependencies, since dependencies were only done at the solution level).
There are also some issues with more complex projects in the new system; specifically, all resulting binary projects need to have explicit references to every dependent library to build correctly, whereas previously they could be effectively inherited from other dependent libraries. Same underlying cause, though.