How to connect single.c/.h files to cmake project? - c++

So, I'm new to cmake and have some troubles. I have simple cmake project that contains a few .h and .c files. I've searched C code at github which consists of only one .h and one .c files. And i want to use some functions from this pack, but i don't want to put this file in my project directory. I want to keep them somewhere outside the project directory. So, how to connect them to project, how to make header visible for project and use #include "name.h" for watching and
and using available C functions .c/.h pack in my project.

Create some other directory in your project, such as misc/ and put the files there. Then use it in your code via "/misc/name.h"

Related

Adding multiple source files to build in Eclipse

I'm developing a code which uses Easylogging++ as the underlying logging library. Recently, I wanted to update the library since it has some high visibility / high impact bugs and I found out that the library is divided into two files (.cc and .h). This new structure needs inclusion of the .cc file in the build string alongside the main program code.
I'm using Eclipse to develop the project and generate the make files to build the project. I need to tell Eclipse (Oxygen.1) that it needs to compile the .cc file alongside the main file while building the project, however I was unable to do so. Any help is greatly appreciated.
It's easier than I thought. Eclipse's managed build is more intelligent than it seems. Adding many source files under the /src folder causes Eclipse to automatically compile all the files under that folder, unless you exclude them.
This means adding the .h to /lib folder and the .cc file to the /src folder and modifying to .cc to look for the .h file under /lib have solved the problem neatly.
To complete the compilation I had to add some flags, since the developer likes to extensively modify his library between releases.
Everything is working fine again.

Import idl files into Visual Studio (C++)?

I am trying to build an application using the BlackMagic DeckLink SDK. They have a folder in their package which has a bunch of .idl files. The manual says I have to inlcude the idl file. Whats the best way to include this file so I can access its code?
I've tried putting them in the source files folder next to the main class but I still get errors that they can't be accessed.
IDL file it self can not be accessed directly.
First you have to generate associated ".c" and ".h" files.
Then you can consume those files by including in your project.
This process of generating "c" and "h" files, you can make it as a part of your build process.
Add the IDL file to your C++ project in visual studio.
Go to properties, you will see "custom build tool".
You can build the idl from there and create the files (.c,.h) in a known location and include them.
The below link has a screenshots explanation, regarding commands to use and how to specify custom build.
https://community.rti.com/howto/how-add-idl-file-visual-studio-project
So for your project, add all your IDL files to C++ project (say IDL folder), and provide a custom build to every IDL file (as explained in above link) , and create the output "c" and "h" files in a directory (say "generated"). Then include the headers and "c" files as required, from the "generated" folder into your project.

Include c++ files outside project directory in Eclipse

I have a problem regarding including files that are outside project directory (c). So I have a project in a workspace. There is a folder somewhere on my hard drive, containing a pair of .h and .c files. I would like to use them in several projects, that's why I wanted to place it outside the project.
I tried including this folder, .h file actually in many ways, but the compiler doesn't seem to see the content of it. I can successfully include the file, but the functions inside are not visible.
In the properties of the project -> C/C++ General -> Paths and symbols I have added the folder. What else should I do?
Add the relative path of all those *.c and *.h file.
#include "path_to_header/lib1.h"
#include "path_to_file/file1.c"
I was wondering about the same recently, here is what worked for me:
You have to mark the files as source code. Open project properties dialog and go to source location tab
then you can use Link Folder to select absolute path or you can use the variables to keep it relative to project file or workspace.
For other configurations Add folder was enough since they were already linked.
You also need to add include paths to c or c++ here
There probably already are some default paths so just add the new ones.
It can also be relative using variables.
I had more sub folders so I added them individually and did not use and relative path in #include at all.

How do I share C++ source code files between projects in Visual Studio?

I'm writing a cross-platform application. One version will work under Win32 and the second on Windows Phone.
I'd like to reuse my C++ core - especially that there are no platform dependencies inside, STL only. I order to do so, I want to use the same source files in two projects: static Win32 library (.lib) and Windows Phone Component (C++/CLI).
How can I configure these two projects to use exactly the same source and header files?
OK, let's take an example. Let's say, that I have project:
MyApp.Library [win32 lib]
myClass.cpp
myClass.h
This library is compiled to .DLL file and then imported in a Win32 application:
MyApp.Win32App [win32 C#]
Since Win32 is not compatible with Windows Phone on the binary level, I cannot use that library directly. But since the library uses only STL, I can create a Windows Phone component, put all its sources there, and build.
MyApp.Component [Windows Phone component]
myClass.cpp
myClass.h
I want these two files to be exactly the same ones as used in the library. How should I organize the project to achieve this effect?
You can add source code from a common location to multiple projects. I do that a lot; I have code in a common directory that is at the same level in the directory hierarchy as most of my project files. It's simply a matter of adding .h and .cpp files from the common directory to your various projects.
I did notice that VisualStudio gets a little cranky and difficult if you use a network drive for common source, so I don't do that. But so long as all of your source code is on local disks, and the IDE knows where to find them, there is no problem having the same source file in very many projects.
one way is to put all .hpp and .cpp files into a seperate folder - call it "Shared".
Then add an additional include Directory inside your solution configuration property - this directory must be a relative path.
Then add ONLY the .cpp files relative from that shared folder into your project
NB! If you have include "stdafx.h" inside your .cpp files in the Shared folder, then comment those out.

Header files not found

I'm adding unit tests (SenTest) to my existing XCode 4.2 project. XCode is complaining that it can't find the required Box2D header files. For instance,
Box2D/Dynamics/b2Fixture.h file not found
The Box2D source files are added to my project under the "libs" group. The header files are found without a problem when building the non-test target. Obviously, I can't add the header files to the test target, but I've added all of Box2D's .cpp files to that target. That just resulted in more of the "Lexical or Preprocessor Issue"s, as above.
How do I tell XCode where to find these header files?
I don't believe you need to specify the folder when referencing a .h file. If only the .h file is added to the project in any group or subgroup XCode is able to find the path when you reference the .h file by the name only.