How to setup jsoncpp library on XCode? - c++

After downloading JSON-CPP 0.5.0 and extracting it, I've no idea how to add it to my project on XCode. I couldn't find any steps online as well. Help please..
I've also tried the steps in ReadMe file. But stuck after installing SCons.

SOLVED:
Step1: Just add all the files inside the include directory and src/lib_json directory anywhere in the project. (.h, .cpp etc.,)
Step2: You have to change the include file paths from #include "json/writer.h" to # include "writer.h" everywhere. If you don't like the name "writer.h", you can very well rename it to "json_writer.h" or whatever.
Step3: In the project settings, under Build phases, add the cpp files(that you added in step1) in the "Compile Sources".

Related

C++ cannot open source file, additional directory listed

I am using Visual Studio 2019, and I'm trying to include codes from open source GLFW. Things were working completely fine, but when I tried to make another project based on this method again it's not working.
It shows 'Cannot open include file: 'GLFW/glfw3.h': No such file or directory'
I reproduced the steps to add GLFW and it worked well. You could check whether there are any missing steps.
Create a Dependencies folder in your project directory, copy the include and lib-vc2019 folders of glfw-3.3.2.bin.WIN32 to Dependencies.
Set Configuration to All Configurations and set Platform to Win32
Add $(SolutionDir)Dependencies\GLFW\include in Proeperties->C/C++->General->Additional Include Directories
Add $(SolutionDir)Dependencies\GLFW\lib-vc2019 in Proeperties->Linker->General->Additional Library Directories
Add glfw3.lib;opengl32.lib;User32.lib;Gdi32.lib;%(AdditionalDependencies) in Proeperties->Linker->Input->Additional Dependencies

Visual Studio C++ how to add header files in a prefix folder

I cloned a github C++ repository. The repository is not a VS project. So I manually created a VS C++ blank project and added the files from the repo to the project. The files are not copied. This is not the problem.
The repo directory looks like this:
include\NTL\*.h
src\*.cpp
*.h means a bunch of header files and *.cpp means a bunch of .cpp source files.
The problem is that the .cpp files have #include <NTL/*.h> and when I build, VS fails to locate the header files (No such file or directory). Adding the path to the include to the Include Directories in project properties didn't help.
EDIT: After some experimenting, I've found that the error has nothing to do with the prefix NTL in #include <NTL/*.h> but with whether the files are copied into project directory. Even though the files appear in VS project view, they must be copied into the project directory.
EDIT: The only way I've managed to get the project to compile is to put the whole NTL directory containing header files in project directory. Include Directories and Additional Include Directories in project properties don't seem to have any effect.
All previous No such file or directory errors were the result of some combination of:
Mismatching project properties Configuration and Platform
Some .h files were actually missing from NTL github repo, e.g. mach_desc.h.
The solution to the problem consists of the following:
Under project Properties > C/C++, add the path to the include to Additional Include Directories.
VS project has a separate set of properties for each combination of Configuration and Platform. Make sure that step 1 applies to the active Configuration and Platform. E.g. If the project's currently configured to build for Debug x64 (active Configuration:Debug and Platform:x64), make sure that step 1 applies to Debug x64, and not something like Release Win32 or Release x64, etc.
Use the Windows/Linux-specific zip package from the Downloads page of the official website https://libntl.org/download.html

How to add Eigen library to c++ project

Probably a dumb / simple question, but I have not been able to find an answer. I have no clue how adding libraries works with CodeBlocks c++. I downloaded the .zip file from http://eigen.tuxfamily.org/index.php?title=Main_Page and extracted the files into my directory. How can I use this library now in my project?
Add one line of code to your source file where you want to use Eigen.
#include "Eigen/Dense"
Put Eigen (extracted zip file) in a directory where you put your existing working header file.
Personally I had no idea how to install eigen on code blocks, but those are the steps I made and it worked:
unpack the ZIP into some arbitary folder
go to codeblocks Settings-> complier-> Search Directories-> Add-> enter the address of the folder you chose in (1)-> o.k
declare #include "Eigen/Dense" before the main function.
I learned the steps from here
This one was a tricky one for me. I am using Code::Blocks Ver 17.12.
a) I downloaded Eigen 3.3.5 (http://eigen.tuxfamily.org/index.php?title=Main_Page). The zip file downloaded is named as "eigen-eigen-b3f3d4950030"
b) Extracted the file to my project folder.
c) Changed the name of the extracted file from "eigen-eigen-b3f3d4950030" to "Eigen3" (you can choose any name).
d) Inside this folder, you will find other folders such as bench, blas, cmake, debug....
Now you have to add the library files for your project (so that the compiler knows where to look for the required library files).
e) In codeblocks, click on Settings --> Compiler --> Search Directories --> Compiler
Click Add and add the Eigen3 folder (the downloaded and extracted folder which was renamed in previous step 'c').
Once added, click on Linker tab (just beside 'Compiler' tab) and add the same path to Eigen3 folder.
f) Now click on Build Options tab, which is found besides 'Search Directories' tab.
g) Tick the "Explicitly add currently compiling file's directory to compiler search dirs"
h) Tick the "Explicitly add project's top-level directory to compile search dirs"
i) Click OK.
Now your build should work and the compiler knows how to search for Eigen libraries.
Any issues, just post it here.
Best wishes
Shre
in my radio astronomy project i install Eigen by the following command:
sudo apt-get install libeigen3-dev
my cmake automatically find the eigen header which i used. it is a sample of my header
#include <eigen3/Eigen/Core>
It's a template library. You can put it anywhere as long as it's in the path (accessible).
Just include the proper headers and it should work. No need to link anything, everything is in the headers.

CMake Xcode using wrong files in Issue Navigator

I generate an Xcode project from CMake that builds a static library and test executable.
After the library is built, there is a file copy operation that moves the headers to a central directory (an include folder next to the built library).
This directory is not listed in the header search paths for either project (I have verified this inside the Xcode project and CMakeLists files).
When I am working in the generated Xcode project, the Issue Navigator will open the files in the central directory instead of the files used to build the project.
Can anyone tell me why this happens and how I can fix it?
Thanks for your help.
Use a separate build directory. Create a new directory. Navigate to that in terminal and say :
cmake -G Xcode <path_to_source>

Opencv - Can't find header files

I'm trying to start development with opencv. The problem is, until now I coul barely setup the opencv cos I cant find its header files.
I made some research regarding to this subject but none of them were realy helpful, below some of the links:
Where are the opencv2 include files?
http://answers.opencv.org/question/14712/opencvhpp-not-in-opencv2/
I made the built the files using CMAKE GUI - Built the code with MVS 11 x64 both debug and release. The compilation suceeded and I cant found libs and dlls, but no headers at all anywhere.
Checkout the pics:
Opencv2 folder
Local folder
So, now I ask, What am I missing here?
Thanks for the help
EDIT ONE:
Is that what you meant?
EDIT TWO:
I found some headers inside the source of opencv, and each of them is inside an specific folder, like core, highgui and so on - that is it? or something still wrong? cos I thought I should take the headers on the build, no on the source..
append "opencv/build/include" to your include path.
if you built the opencv libraries yourself using cmake, make sure you run the INSTALL project, and add the folder, where it installed to.
When you run make install then the include files that you need are copied to a single directory determined by the makefiles and probably displayed as a part of the output.
I know what's going on. After built the entire solution, under the "opencv" solution strcutre, there is a folder called "CMakeTargets", expand this folder, you can see "INSTALL" project, and right-click this project, then select "build" option, then after installation, all libraries and head files will be located at the correct path. Like the following picture shows:
here
Take a look at the settings that were in use when you built OpenCV - the include path must point to where the include files are for your build to have succeeded.