How do I use the Crypto++ library within Eclipse? (C++) - c++

I'm having trouble getting Crypto++ to work from within the C++ Eclipse IDE. I think I installed it correctly, but every time I try to do any sort of include in the file so I can use the new library, it does not compile. It will compile C++ normally, but it won't let me use the new library. (Bear in mind, I am not too familiar with this whole process with libraries as a whole.)
My process:
Downloaded 7.0 from here: https://www.cryptopp.com/#download
Unzipped it into a folder on my Desktop called Crypto++
Created a new project, it compiled.
Right click on new project, properties -> C/C++ Build -> settings ->
Tool settings
Clicked add, file system, and then clicked the folder I created, and
hit apply.
So, it is listed under library search path, but this include does not work:
#include "cryptlib.h"
Did I install the library properly, or am I missing something?
Edit:
fatal error: cryptlib.h: No such file or directory

Related

Build failed with no stated reason on Segger Embedded Studio after adding custom source files

I'm modifying a simple example project (blinky) from the nRF SDK. I added a header file and a .c file in a new folder inside the project directory then added that path ./lib to the common preprocessor user include directories. I then included the header to main.c.
I can compile the new library on its own but when I build the whole project, I get Build failed error with no stated reason to follow up.
Here is an image of that:
Does anyone here know how to beat this?
I haven't used Segger Studio specifically, but it seems to be the CrossWorks IDE underneath.
In CrossWorks, you have to do the following:
Download & install all relevant libs from inside the IDE, under Tools -> Packages -> Install packages. Grab your specific target MCU as well as any specific boards or libraries you'll be using. In case some needed lib is missing here, you will get very weird errors.
In the project, click on the project name itself in "project explorer". Then in the properties window, check settings (this is a bit different in different versions of CrossWorks, might have to right click and pick properties in older versions). Under "user include directories" you should have something like this:
$(DeviceIncludePath)
$(TargetsDir)/NameOfMCU/Include
$(PackagesDir)/CMSIS_4/CMSIS/Include
$(ProjectDir)/NameOfDirectory
Where "NameOfMCU" is the name of the MCU family used, CMSIS should be there in case you are using any ARM, "NameOfDirectory" is the name of your custom directory (you can add several).
Also, get the debug build working first, before switching to release build.

How do I add the boost library to Xcode 11? C++

I cannot find a way to add boost in Xcode 11.2.1. I found a setting under the target called "Frameworks and Libraries". I dragged the boost directory there, and it got added to the "Frameworks" section of the project. However, in building the project, it says "file not found". For example:
#include <boost/lambda/lambda.hpp>
results in a "file not found" error. Instead of adding boost, I dragged the entire include area of Macports. It took a while for Xcode to parse through that, but I get the same error. So, under Frameworks it has "include", but it cannot find the relevant hpp file, even though I checked and it's there in the boost tree.
I have installed boost via Macports. It resides in /opt/local/include/boost.
In the Xcode documentation, I saw a reference to "USER_HEADER_SEARCH_PATHS". I figured how to set that in a configuration file, so I added a configuration file to the project. I added this to the configuration file:
USER_HEADER_SEARCH_PATHS = /opt/local/include/boost
but that does not work either. (If I remove the boost, that does not work either).
When I select "include" in the Frameworks location of the project, I see that there are different settings "Identity and Type" for that object (right side of Xcode window). I selected "absolute path" and it shows the full path as /opt/local/include which is correct. However, this does not solve the problem either.
Do I need to create a link in a pre-defined area so that Xcode can find it?
I did find a rather ugly work-around: create a soft link to the boost library in the same area where the STL resides (within the Xcode.app directory structure).
Using the setting only works with individual files. I can add individual file to the setting (via drag and drop), but it won't follow nested directories, so clearly this will not work for a library implemention such as boost.
I prefer to keep dependent libraries inside project area. So here is how I just do it for test:
Create new TestBoost project in Xcode from macOS Command-line App C++ template
(now there is TestBoost folder where TestBoost.xcodeproj is located)
Download latest boost boost_1_72_0.tar.gz and unarchive it
(now there boost_1_72_0 folder with boost)
Copy boost_1_72_0 folder inside project TestBoost folder, so it is located aside of TestBoost.xcodeproj
In Xcode Project Navigator select TestBoost project > select TestBoost target > select Build Settings tab
In Search Paths section select Header Search Path, double click on value area and enter ${SRCROOT}/boost_1_72_0 (leave non-recursive flag)
Delete default main.cpp from TestBoost target (to avoid main function confusing) and add some example from boost for testing, eg. boost_1_72_0/libs/algorithm/example/search_example.cpp
Build & Run > Success
Output:

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.

Using framework header files in Xcode for C++ project

Im having trouble to use Gecode (http://www.gecode.org/download.html) framework for my project.
I downloaded and installed the framework. Now it can be found under
/Library/Frameworks/gecode.framework
I created a new "Command Line Tool" project, and selected "C++" for the type.
Then I opened the Target of my project and added gecode.framework in Build Phases -> Link Binary With Libraries
In Build Settings for the path i added following path for "Header Search Path" : /Library/Frameworks/gecode.framework
Now i tried to build a sample code with following includes:
#include <gecode/driver.hh>
#include <gecode/int.hh>
#include <gecode/minimodel.hh>
--> Xcode is complaining that file is not found.
I tried to compile in terminal with g++ and llvm-g++, it compiles without any warnings or errors
To make GeCode or any other framework work in Xcode you need to do the following.
Install the framework (Obviously!! GeCode Link here)
Open the project in Xcode
Select the project file from the project navigator on the left side of the project window.
Under Linked Frameworks and Libraries, click the + sign.
Select the framework from the list display or else click on Add Other if your framework is not found in the list.
Press Command+Shift+G and enter the path directly. In my case for gecode it was /Library/Frameworks/ and then select the desired framework you want to include in your project and then press open.
Go back to you project file and press Command + r and Voila!! it should work.
Cheers!!
Well, i don't have the full solution, but part of it: add the path of your frameworks (e.g. /Library/Frameworks) to the "Framework search path" of your projects.
After that, the compiler does not complain anymore, and autocompletion works fine. But the linker still complains about some symbols not found, when linking.

How to start a CodeBlocks project from external code and Makefile?

I have C++ code that depends on boost and other libraries, and therefore this code has a makefile that invokes boost.
I am now trying to start developing this code in CodeBlocks in linux, so in order to do that I have two basic questions:
(1) How can I import the code into CodeBlocks as a CodeBlocks new project? This seems to be a good rec: http://www.programmingforums.org/thread44976.html
(2) How do I invoke the makefile with CodeBlocks instead of CodeBlocks trying to compile the code (which would fail since CodeBlocks do not know that it needs to invoke boost)?
How can I import the code into codeblocks as a codeblocks new project?
File > New > Project > Empty project
Create the project, then:
right click on the project name on the "Projects" pane;
add files recursively.
I recommend that you create Code::Blocks project new project at the top-level of your source (and not e.g. in a dedicated ~/codeblocks directory), or else it will show long file paths.
How do I invoke the makefile with codeblocks instead of codeblocks trying to compile the code (which would fail since codeblocks do not know that it needs to invoke boost)?
Asked at: Is it possible to use an existing Makefile to build a project in Code::Blocks?. For quick reference, the solution is to go to Project > Properties and toggle on the option This is a custom Makefile. Further options can be specified from the same window.
Most projects can be compiled without a makefile, so just include files, and if you need an extra library include that in a project. If your project uses header-only boost libraries and you have packet installed libboost-dev (this is on my Debian) then it is included automatically. Else just use the proper library name in settings (I can't remember if you need to append l to the name).