when creating a new C++ console app VC++ gives C libs? - c++

I recently tried making app windows using C in VC++ 2010.
I changed some additional dependency settings for my project. But after doing this, every time I create a new C++ project VC++ gives me what is to be believed C external dependency lib files despite giving cCand C++ extern dependency libs.
What have I done and how do I fix it? As its starting to do my head in to be honest.

The "External Dependencies" folder in your project contains a list of headers that the C++ IntelliSense engine has determined are used by your project.
The "External Dependencies" folder in no way impacts how your project is built (you can even disable the folder, under Tools -> Options -> Text Editor -> C/C++ -> Advanced -> "Disable External Dependencies Folder"). It is there for informational purposes.
If you include a C++ header (<vector>, for example), then right click your project and select "Rescan Solution," you should see the header file <vector> and all of its dependencies appear in the list. (You probably don't have to use "Rescan Solution," but I'm not 100% sure on what events cause the C++ IntelliSense engine to pick up new header files.)

Related

How to use an external library for C++ in VS2017

I've been programming in Python for over a year now but am just learning C++ and am unfamiliar with how to go about using external libraries, CMake and github for that matter. I'm trying to use an external library called cpr - https://github.com/whoshuu/cpr. So far I've followed the instructions in the 'Usage' section of that link up to, but not including, the "add_subdirectory(cpr)" bit.
So far I've got the source code for cpr in the Visual Studio project folder of my C++ project. In the project properties I've then added into Include Directories (under VC++ Directories) "$(SolutionDir)site_libs\cpr\include" and I've added the same thing into Additional Include Directories (under C/C++ -> All Options). This means that the following code compiles just fine:
#include <cpr/cpr.h>
int main(int argc, char** argv) {
auto r =
cpr::Get(cpr::Url{"https://api.github.com/repos/whoshuu/cpr/contributors"},
cpr::Authentication{"user", "pass"},
cpr::Parameters{{"anon", "true"}, {"key", "value"}});
r.status_code; // 200
r.header["content-type"]; // application/json; charset=utf-8
r.text; // JSON text string
}
However this code isn't working when it comes to building, due to link errors. I'm pretty sure the thing I'm missing is the actual .lib file for it to find where these functions etc are defined (nothing for cpr is set in the Linker -> Input property). So I'm wondering - how do I create this .lib file / is that even the right thing to do / what is this "add_subdirectory(cpr)" and where/how do I run it... basically what do I do to make this whole thing work..?! I've tried compiling cpr with CMake but it throws a load of errors about 'CMakeLists.txt' not present in certain folders.
Apologies if I've used any incorrect terminology here, only been learning C++ for a couple of days now. Any help massively appreciated!
If the library does not come as a binary distribution (that is with the .lib already built) you are going to need to build it as a separate project from the code you want to use the library, that step will build the .lib file. If a .sln is included with the distribution use that otherwise you may well have to create your own (or add it as a project to an existing solution).
Once you have a .lib add the directory under the VC++ directories of the project settings and add the actual .lib file name under Linker->Input on the Additional Dependencies line.
To build the library if the distribution does not include the needed VS files you will need to create a project at minimum (it can be part of the solution for your program), right click on the solution node in solution explorer and select Add->New Project, from there select Visual C++->Windows Desktop and either Dynamic Link Library or Static Library as you desire.
Go to the Project menu and select Project Dependencies, change your program to depend on the new project, this will set build order so your program project builds after the library.
You may need to disable the use of pre-compiled headers, right click on the new project node select Properties, go to C/C++->precompiled headers and change Precompiled Headers->Precompiled Header to Not using precompiled headers.
Next add the header and source files to the project and attempt building.
If this succeeded you will have a .lib suitable for use in the additional dependencies of your program project as already described.

Eclipse Indigo CDT code completion

I am using Eclipse CDT as IDE to develop my application which uses an external library for which I have access to the header files and libraries.
How can I setup my project properties such that I can get code completion (I have code completion for files which belong to my project, but not to the ones which are part of this external library).
I tried the following approach which unfortunately fails.
Project->Properties->C/C++ general->Path and symbols -> Includes
In Includes, I added the path to the header files.
Unfortunately, this does not seem to work.
So how can I setup my project such that, if I instanciate an object (from this external library) in my project, I can get code completion and see all available public methods?
thanks for your valuable help.
This works for me: Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> C++ -> CDT User Setting Entries -> Add

Visual Studio 2012 - error LNK1104: cannot open file 'glew32.lib'

I am having issues compiling a basic openGL program on VS 2012. I get a build error upon compiltation giving me:
1>LINK : fatal error LNK1104: cannot open file 'glew32.lib'
I followed the instructions given to me by the documentation for GLEW.
In your OpenGL project open Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies -> add glew32.lib.
Also you must include #include in your sources; For that add path to your glew folder: Project -> Properties -> Configuration Properies -> General -> VC++ Directories -> Include Directories and Library Directories;
C/C++ Tab -> General -> Additional Include Directories - Add lib folder there
I have also added the glew32.dll onto my Debug folder within my project folder along with the executable. So far I keep getting this error.
If you need any more further clarification of the steps I have done please don't hesitate to ask
In all honesty, there is no real benefit to using the DLL version of glew (short of reduced executable size, but this hardly matters on modern Windows PCs).
It is not like you can simply drop a new version of the DLL into your application and use extensions that you never used before. Likewise, bug fixes are so infrequent/unnecessary with a library that basically just parses the extension spec. files that using the DLL as a means of fixing extension loading bugs in shipped software is also not practical. Statically linking to glew (this means glew32s.lib) makes much more sense in the long run.
The static linking library is also more portable on Windows, it will work with MSVC and MinGW (whereas the DLL library only works with MSVC). Link against glew32s and put that in whatever directory you decided to use for additional library dependencies.
Here is a sample solution configuration for a project I wrote that uses glew. I have established a convention for this particular software where compile-time dependencies are stored under platform/<Subsystem>. Thus, I have glew32s.lib (32-bit) and glew64s.lib (64-bit) in ./Epsilon/platform/OpenGL/glew{32|64}s.lib
Steps to Use Classes form another project (Add header and solver linker errors)
To be able to add the header from another project, first go to "Properties > c++ > General > Additional Include Directories" and add the directory that contains the header. Now you will be able to add the header of the class from the other project, but running the project will still cause Linker Errors.
Add __declspec(dllexport) before the class you are using for the other project. This can be added in the header file of that class. This should be added right before the function or variable or class name. Now you will get a lib file. (if placed in wrong place, you can get this warning: https://msdn.microsoft.com/en-us/library/eehkcz60.aspx)
"Properties > Linker > Additional Library Directories". Specify the location of the lib file that is generated.
"Properties > Linker > Input > Additional Dependencies”: Add the name of the lib file.
This sounds like the library has been specified as a dependency, but the linker/additional search path(s) has not been set to include the directory where the library is located.
This may help.
It happened to me under this situation, I clean the solution and build it again, then many errors like LNK1104 occur.
After trying to restart IIS, I build solution successfully without LNK1104 errors. I do not know why, but restarting IIS takes much more time than normal, so I guess something is used by other IIS worker process.
Just give a shot to see if this magic happens on you.
This question is old and marked solved, but I had a similar problem symptoms with a completely different solution. So just in case anyone else stumbles in here:
It appeared that because I had 2 projects under one solution (a dll and an exe), the building order was mixed (from the output window):
1> Rebuilding project1..
2> Rebuilding project1..
1> file1.cpp
2> file1.cpp
and so on. By the message you copied, it appears you too have more than one project under one solution. One project was looking for the *.lib file that the other build hadn't created yet.
Solution:
Right click on "main" project -> Build Dependencies -> Project Dependencies.. -> Mark which project the main one depends on.

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.

How to create project dependencies in netbeans (c/c++ plugin)

As I work on a c++ application, I realize I am making a lot of classes and functions that could be used in other projects. So I'd like to put all this code in a separate net beans project that can be "included" into other projects. (with code completion etc)
I've tried creating a new "static library" project, then I added the project to my main project (by going to preferences->link->libraries and adding my "library project"), but the code completion feature does not find the .h file of my library project when i try to #include it, the project also won't build.
What is the correct way to do this?
Creating a static library and adding it to Linker->Libraries is correct.
But another small step is needed: add directory with shared *.h files to project properties -> C Compiler (or C++ Compiler) -> Include Directories.
Also take a look at Subprojects sample: File -> New Project -> Samples -> C/C++ -> Subproject Application.