1

Apologies for a very basic question. I am trying to port from a CMake project into a visual studio project. Basically I want to run the project from visual studio without using the CMake file. In the project I need to port, there are many folders and sub folders that contains many .cpp and .h files. These are included to the main cpp file as using #includes.

My Case

The library I want to include Glimpse of the library Libpfs

and my main.cpp

My Main.cpp For instance to make things simple assume I have a main file main.cpp and this file includes #include "Libpfs/colorspace/colorspace.h". The Libpfs is a folder and it has many sub folders one of which is colorspace folder and this has many .h and .cpp files. One .h file is colorspace.h that is included in main.cpp using the #include and the folder also has .cpp file i.e. colorspace.cpp.

My Attempt

My objective is include them to my project. Now here is what I have tried in Visual Studio Project->properties->C/C++ in Additional Include Directories I gave the path of the folder that contains Libpfs but this approach did not work and gave linker errors this might be because I have no lib files for the Libpfs (correct me if I am wrong). I only have .cpp files of the corresponding .h files. I presume the cause of error is the the .cpp files are not compiled yet.

My Question

How can I include the cpp file to my project as well (not the lib files since I dont have those).

7
  • You shouldn't typically include cpp files of a library, but link to the compiled .so .lib .dll or so. If you set an include path use #include <bar/foo.h>. P.s. a good library would have a seperaat "include" directory with only headers.. Commented Jan 21, 2021 at 6:43
  • Just add the cpp files to the project and they'll get compiled and linked Commented Jan 21, 2021 at 6:44
  • Thanks @JHBonarius. But what if I dont have the .lib or .so or .dll? Commented Jan 21, 2021 at 6:44
  • @AlanBirtles Does this mean I would need to add every .cpp file of the 3rd party library to the project? Commented Jan 21, 2021 at 6:46
  • 1
    Have you tried 'right click on project in solution explorer/Add/Existing Item...' to add all the cpp files and h files to your project? That's the normal thing to do. Commented Jan 21, 2021 at 7:07

2 Answers 2

1

Using this for a source, I find the CMakeLists.txt to contain nothing special.

FILE(GLOB COLORSPACE_H *.h)
FILE(GLOB COLORSPACE_HXX *.hxx)
FILE(GLOB COLORSPACE_CPP *.cpp)

SET(LIBPFS_H ${LIBPFS_H} ${COLORSPACE_H} ${COLORSPACE_HXX} PARENT_SCOPE)
SET(LIBPFS_CPP ${LIBPFS_CPP} ${COLORSPACE_CPP} PARENT_SCOPE)

So you can just add all the files to a VS C++ project. I would use some directory management, to separate these sources from your own.

But anyhow, in that case, you should include the sources by relative path. E.g.

#include "../../Libpfs/colorspace/colorspace.h"

Alternatively, you could put everything in a separate C++ library (static .lib or dynamic .dll). In that case you should but the binaries in in a bin path and add that as additional library directory (project properties of your own project) and put all the header files in an include/Libpfs path and add that as additional include directory. In that case you should include the files as.

#include <Libpfs/colorspace/colorspace.h>

On another topic

#define pow_F(a,b) (xexpf(b*xlogf(a)))

I found this define only in the sources of the same source used above. It seems to be sourced from sleef and according to this it should give a speedup. But you should measure if that is really still true, instead of doing copy-paste/cargo cult programming. I think generally you should use the standard library std::pow, which has overloads for float, double and long double. The compiler will in most cases optimize its use for you.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes the source is right. Adding sources by relative path would require each and every cpp file to be changed to relative path. Which I dont want to. The alternative option can be opted but the problem is there is no .lib or .dll available for the project.
will adding the path of .h files in the additional include directory and by loading all the cpp files to sources of visual studio project work?
"there is no .lib or .dll available for the project." <-- then make your own. Second question: probably yes. But probably also need to change paths.
0

open explorer , look for C:\Program Files\Microsoft SDK\ and then go after dir with alot of .lib's in its \lib . it's an msvc source for .lib and other stuff like that . copy your library there

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.