netbeans projects that depends on other projects and their includes - c++

I have a certain c++ (library) project in netbeans 7.0. Lets call it the A project.
Now i have a c++ (application) project called B.
B depends on A:
1) at compile-time for some includes in A project
2) at link-time for the libA.so
2) is pretty easy, since i just need to go to project properties-> build(linker) -> libraries and click "Add Project.."
However its not that clear what the best nice, clever approach for 1) is. I've created pkg-config entries in the past to help projects find third-party libraries, but is a bit more work to do it for projects themselves. I could also include existing file directly, but i would have to add ugly ../../A/ in the includes which is PRECISELY what i'm trying to avoid
So I would like to hear about people solving this problem in the past and what was the best solution they found

You can add "an additional library directory" in the linker portion of the project properties. Then you can refer to library file "A" without the path specifier. This is a command line option to the linker to search that directory for libraries it has not found.
I'm not sure if they've added that option to the project properties for Qt projects in 7.0 or not. It's missing for those projects in 6.9.1

Related

How can I install and use C++ libraries on eclipse?

I want to use libosmium library. Could someone please tell me how do I set up this library after I download it?
All I need to know is the standard way of installing external libraries. I can't really find very clear instructions online.
I'm coding with C++ using the eclipse IDE version 4.18.0.
For includes: right click on your project and go to Properties>>C/C++ Build>>Settings>>GCC C++ Compiler >> Includes
you must add the include path for the external library (where the header reside). This information is needed by the Eclipse indexer (code completion etc.) and the compiler
For libraries: right click on your project and go to Properties>>C/C++ Build>>Settings>>GCC C++ Linker >> Libraries you must add the library search path (option -L) and the library you want to link against (option -l). This info is needed for the linker.
Source: http://wiki.eclipse.org/CDT/User/FAQ#How_do_I_add_an_external_library_to_my_C.2B.2B_project.3F
Eclipse-CDT Setting Pictures
Include path settings:
Library & library search path settings
You can also use pkg-config plug in
https://marketplace.eclipse.org/content/pkg-config-support-eclipse-cdt
Here is a link to a similar question with answers: Problems importing libraries to my c++ project, how to fix this?
As specified in the other answer, you can usually add a library by looking at the project properties:
Properties>>C/C++ Build>>Settings>>GCC C++ Compiler>>Includes
However if you're using a makefile project, the Makefile itself must know about the location of libraries. In this case, in order to avoid an "Unresolved inclusion" warning in the header, you may also want to tell eclipse where the header files are. This way the autocomplete & "Open Declaration" will work. This is found in:
Properties>>C++ General>>Preprocessor Includes Paths, Macros etc.
In my case I couldn't figure out how to add a custom configuration and updated the default configuration. I added a path for the Android NDK under the GNU C++ -> CTD User Setting Entries

Add a C++ dll in Visual Studio 2012 - No references folder

Ok, so I've seen a few tutorials tell me how to do this but my interface and results don't match theirs. I've done this a lot myself with C#, and I don't get why the difference is.
*I have a third party dll (and lib, and .h files)
*I have a project in Visual Studio 2012 Express
*I want to add the dll to the project (I believe what I want is to implicitly link).
There is no References folder in my Solution Explorer. If I select [Project > Properties > Framework and References > Add New Reference] then all it will show me is other projects in my solution. I've looked around at the project options (Linker > Additional Dependencies, etc) but there are a lot of possible places which might do something (or not) in who-knows-what combination.
C++ and C# are different. when you choose c++ project it requires different approach than C# to configure things. You have to add first you header files path in additional include directory then you dll path in linker and dll name in linker input in project settings.
Add the .lib file to the Project -> Properties -> Linker -> Input -> Additional Dependencies field, and #include the .h file. The .dll file will need to be in the search path which is documented here.

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.

Using sub projects in Visual Studio

I am quite used to Linux development and Makefiles, and started using (Windows and) Visual Studio not so long ago.
What I want to do is (I think) quite simple, but I can't seem to find how to do it using Visual Studio.
I have to write an application, which I can divide into several independent sub-parts. I want to work incrementally, and create several projects that together with a main file will end up with my full project.
What I basically want is to be able to write a small project, have a main for it so that I can fully test it, and use it as a dependency for the next project. In this case, the smaller main would be deactivated (or I can comment it), and I would just change the startup project.
If I find a bug in a subset while writing my bigger software, I could just change the startup project and solve it at a smaller scale.
Well, that's what I do all day long in Python and Java.
I tried to create new projects into my project, but I always end up having linking problems, where my main projects knows about the files in the sub projects, but not the smaller ones, etc. . .
So, is there a guide somewhere I can find to work this way ?
Thank you
For individual projects:
Every individual project property sheet has a C++ options page. Here you can specify the 'Addional Include Directories' in a comma separated form.
Similarly, there should be a property sheet for Linker where you can specify the 'Addional Include Dependencies' and the names of the libraries it depends on.
For linker dependencies of the main executable:
Go to that main project, go to its properties, go to common properties and select 'Framework and References'. This should give you a list of all the projecs that are in your solution. Keep adding them and Visual Studio should add the right linker flags automatically for you.
Sorry, have no access to the computer now else would have provided exact steps. Visual Studio can get tricky sometimes but once you use it, you'll be amazed by what it can do for you. Personally, I love it.
Hope this helps.
Thanks to Vaibhav, I was able to find a solution:
I had to :
change subproject type to lib instead of exe
Add the subprojects as project dependencies in the main project (this just sets the build order)
Comment out the main of my subprojects, to keep only one active.
Add each subproject include directory in the include repos of the main project, so that the compiler can find the header files
Add the general directory as a dependency for the linker (in this case, it is not the debug/release folder of the subprojects, but the output directory of the complete project).
Add the names of the lib files of the subprojects in additional dependencies of the linker of the main project.
To make it simple, the project dependencies capability of VS2010 just changes the order in which the projects are built. . . I miss Eclipse.
If I find a bug and want to test on of the subprojects, I have to :
change the startup project to be the subproject I want to change.
uncomment the corresponding main
change the project type to be exe instead of lib to be able to compile it.
Debug, and do everything back again to continue working on my main project.
Quite boring, don't you think ?
Looks like you trying to do manual unit testing. Use something like Google.Test. You need to make test project for every lib.
We have directory with static libs projects. Another directory with tests projects. Every test solution contains one exe project and few existing lib projects. Every project have configured dependencies. You dont need to set additional dependencies of the linker manually (paths are evil, out dir for the lib file will be taken from project settings), open project properties with right mouse button, Common properties, Add new reference and select lib project. You only need to set additional include dirs.
When you find new bug - just open test project for the library with bug, add code which cause the bug, fix it, and be happy (and sometimes run all test). And even better - use TDD.

C++ Library Include

I am relatively new to C++ and need to use a library for the first time.
I was hoping someone would be able to show me how to properly [ link to / include ] the library.
The library I want to use is the ID3 v3.8.8 that can be found here:
http://id3lib.sourceforge.net/
I have downloaded the Windows binaries and now just need a way to link to the library.
Files downloaded: Debug/id3lib.dll, Debug/id3lib.lib, Debug/id3lib.exp, Release/id3lib.dll, Release/id3lib.lib, Release/id3lib.exp
I am using Visual Studio 2010.
Any help is greatly appreciated. Thanks in advance.
Before you can do any C++ development with this library you'll need the headers too which are in the id3lib-3.8.3.zip file. You have only downloaded the binaries which will let you run an application that needs those libraries but not re-compile it.
There are several steps, and many a pitfall. If you are a rank newbie at using C++ and VC++ in particular, every step is going to require some (gasp) reading of documentation or googling.
In VC++ 2010, use the Property Manager "C/C++ General / Additional Include Directories" section if necessary to tell the compiler how to find the header-files.
Use the Property Manager "C/C++/ Code Generation / Runtime Library" section if necessary to tell the compiler what version of the Microsoft C Runtime Library the library requires.
Use Property Manager "Linker / Input / Additional Dependencies " to specify the .lib file id3lib.lib.
Use Property Manager "Linker / General / Additional Library Directories" to tell the linker where to find .lib file.
If the dll id3lib.dll is not in the directory where you will start your program, open a Microsoft Explorer window, and right-click on "My Computer." Select "Properties/Advanced/Environment Variables", and edit the user-variable PATH to contain the path of the directory that contains the dll. Be very careful doing this. Before you change it, copy the value that's there originally and save it to a text file, in case you mess up and need to restore it. If you get it wrong, other programs can fail to start.
Good luck.
Add id3lib.lib to your project, that should satisfy the linker and the resulting executable will depend on id3lib.dll.