Cannot compile C++ files with boost and odeint - odeint

I installed boost using brew install boost in order to use odeint library (the odeint webpage says : odeint is a header-only library, no linking against pre-compiled code is required).
I am on Mac Yosemite 10.10.5 . Now when I cd to /usr/local/include, I can see boost directory there. Inside boost (/usr/local/include/boost) there are all the header files I needed for my project, along with the numeric/odeint directories needed for my specific purposes. At the same time, when I cd to usr\local\lib, I can see a lot of libboost_* .dylib and .a files.
However, when I try to compile a c++ file that I temporarily save in ~/Downloads (the first header is #include <boost/array.hpp>), I got the error fatal error: 'boost/array.hpp' file not found.
I am inexperienced in programming, and I really appreciate your help! Thank you!

Use the following include statements and let us know if it works.
#include <boost/numeric/odeint.hpp>
#include <boost/numeric/ublas/matrix.hpp>
If not, some additional info is needed. What is your BOOST version, what is the structure of the /usr/local/include/boost directory, how about including other (non-boost) headers from /usr/local/include (maybe compiler include path is broken).

I asked my professor about this. He gave very detailed explanation, and I think I should share so that everyone can benefit from it:
Theory:
Your compiler needs to know where these files are. You need to find a way to tell it where the files are.
Depending on how you are doing the compiling there will be different solutions. If you are compiling via the command line, use something like
g++ -I/usr/local/Cellar/boost
The -I stands for "include files". There is a similar g++ "switch" called -L for libraries when you get to that stage.
There is also a whole series of tools to tell the compiler how to search for include files. The directory /usr/local/include is almost certainly on the list of places for it to look.
If you are using "make" and the associated tools for compiling, you can add the include directories to part of the "Makefile". Again, the details are different for every setting.
Bottom line -- you'll need to learn more about your compiler system. Find manuals and examples for your specific tools and system. Learn how those tools work and where to specify the boost libraries. Read the boost manuals and learn where they store files and what all the names are for the different directories where these files are stored.
It's not fun work, but it is worthwhile learning about how all the parts get put together.

Related

clang -module-file-info doesn't generate any output

I'm trying to move a cross-compiled CMake project to Clang Modules to see whether compile time reduction is worth it. However, it seems that Clang is generating lots of duplicate modules in it's ModuleCache.
I'd like to figure out why (maybe some CMake config, etc), so I'm trying to run clang -module-file-info on the generated module files.
However, clang's output is just empty whenever I provide a proper module file. Am I doing anything wrong? Is there anything special that I need to take care of?
The files all have a reasonable size (from a few kB to a few MB), look fine in a Hex editor (start with CPCH, have some recognizable strings, etc) and whenever I specify a wrong file (or a file compiled with a different version of clang) I get the appropriate errors.
I've tried with clang 7.0.1 as well as 8.0.0.
I also tried --verbose but that didn't show any problems either.
To answer my own question:
clang doesn't output the stats on the command line, it puts it into a file by default written in the current directory.

How to compile srlua?

I made a program today, and I was wondering on how exactly to make it an executable. I've researched and I've came up with using srlua. I've asked this previously, but I usually mess up on the same instruction. I was told to 'compile srlua' While I know exactly what to do right after I compile srlua, I don't know how to compile them right now.
I've gone through a few YouTube tutorials, and I managed to find one but only in Spanish. I was able to slightly follow along until he downloaded a precompiled version of srlua, where the download link is no longer there at the same page he was at.
Would anyone be able to explain what they're trying to say?
You need to tell CMake where the Lua files it needs are.
For me, the Lua includes are in /usr/include/luaX.X, where X.X is your version number, e.g. 5.3. The Lua libraries may be in /usr/lib (with filenames like libluaX.X.so).
If the locations differ for you, you can try find / | grep "lua.h" and find / | grep "liblua".
Once you've located the folder which lua.h is in, and the appropriate library file like liblua5.3.so, you need to add these to the CMakeLists.txt file in the srlua folder.
For example, using lua5.3, you might replace this line:
include_directories(${LUA_INCLUDE_DIR})
with this one:
include_directories(/usr/include/lua5.3)
And for the libraries, you might replace this:
target_link_libraries(glue ${LUA_LIBRARIES})
target_link_libraries(srlua ${LUA_LIBRARIES})
with this:
target_link_libraries(glue /usr/lib/liblua5.3.so)
target_link_libraries(srlua /usr/lib/liblua5.3.so)
After this, run cmake ./ in the srlua folder, then run make. srlua should be built.
Note: you may also have to remove the line find_package ( Lua REQUIRED ), it was a false error for me (it only built when I removed that line).

Linking Header File with Main.Cpp file in Codeblocks

I am trying to use codeblocks to compile the code available here
The thing is every time I try to build and run, I run into the following error:
|/.../head_pose_estimation/opencv2/core/core.hpp|48|fatal error: opencv2/core.hpp: No such file or directory
Does anyone know how I can fix this? Thank you!
You do not have the pre-built (compiled) version of OpenCV, what you currently have are the source files. If you want to do something special with OpenCV (Target/GPU SUpport etc) then you will need to build the framework using an appropriate guide.
If however you simply want to use OpenCV in the most common way then download the pre-built libraries from the OpenCV.org website.
NOTE:
If you are using OpenCV with MinGW compiler, I do not remember if the pre-built is actually pre-built for MinGW. (I dont think they do) In this case you will HAVE to built the libraries. You can find a guide here

force cmake to compile openCV with llvm

Background
My goal is to compile OpenCV for ios with support for the armv7s (the s is the hard part) architecture but have been unable to make any progress. My most recent theory is that the problem is that the cmake files that come with the library use gcc as a compiler which I do not think supports armv7s (if I am wrong please tell me). I am completely new to cmake however and have not been able to change the compiler.
The reason I suspect the compiler is because of the line
set (CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_BIT)" CACHE string "Build architecture for iOS")
which as far as I know should include armv7s. Changing that line to
set (CMAKE_OSX_ARCHITECTURES "armv6;armv7;armv7s;i386" CACHE string "Build architecture for iOS")
had no effect.
I know there are explanations of how to set the compiler here, here, and here. My problem is that I am trying to change an existing cmake system and don't know what ramifications my changes could have. The code in question can be downloaded here. To build the framework I run the python script in OpenCV-2.4.2/ios
python build_framework.py ~/Desktop
from what I can tell the relevant cmake files are located in OpenCV-2.4.2/ios/cmake. There are only 3 and all are fairly short. My most recent attempt was to change two lines in the toolchains
CMAKE_FORCE_C_COMPILER (gcc gcc)
CMAKE_FORCE_CXX_COMPILER (g++ g++)
to
SET (DEVROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer")
SET (CC "${DEVROOT}/usr/bin/llvm-gcc-4.2")
SET (CXX "${DEVROOT}/usr/bin/llvm-g++-4.2")
CMAKE_FORCE_C_COMPILER (${CC} CLang)
CMAKE_FORCE_CXX_COMPILER (${CXX} CLang)
in an attempt to copy this SO question.
Question
My first and most important question is if this is out of my depth. I have been assuming that changing the compiler/target architecture would be a simple flag set somewhere but I am becoming less convinced that is true. Also, there is an entire directory OpenCV-2.4.2/cmake filled with much larger cmake files that I have been avoiding in the hopes I don't need to worry about their contents. Is this a problem I am going to be able to solve in less than 10 hours?
If you answered yes to the previous question, can you give me any direction? Suggested reading? Am I justified in ignoring the contents of OpenCV-2.4.2/cmake? I have been shooting in the dark for quite a while now without success.
If it turns out this is as simple as I originally hoped, how do I do it?
Update
I never did figure out how to do this, but there is an xcode version of the library here from which the compiling settings can be changed easily.
Set CMAKE_C_COMPILIER and CMAKE_CXX_COMPILIER to what you need.
Edit: this supposes you already had success with building this for armv7.
Edit2: this will just change the compiler.
I see a lot of links in your question, but didn't find original link with information how to cross compile with CMake.
You should not change anything in existing build system.
In general you need to create toolchain file for your target architecture and run cmake with it.
cmake -DCMAKE_TOOLCHAIN_FILE=< your toolchain file > < path to CMakeLists.txt from opencv >

How to include the boost library in a C++ application?

I'm very inexperienced with Linux and the terminal, but I'm trying to learn. I've also never included an external library before. Now I need to include the Boost.Asio library in a program being developed in Ubuntu with G++.
Could someone very kindly and very carefully explain how to go about this, from the beginning?
EDIT:
Expanding on the original question: if I need to send this code to someone else for them to run it on a completely separate machine but in the same environment, how do I take that into account? If this whole process involves literally placing library files into the same folder as the code, do I just send those library files along with the .cpp to this other person?
You have mentioned you are using Ubuntu, so the simplest way to use boost is to first install libboost-all-dev package (from synaptic), which will install everything for you including those that needed to be compiled. Then you just need to use g++ in the usual way.
Please note that whether the version is what you want, if not, you may want to install it yourself. On the other hand, boost is mostly header only library, so you only need to extract the files (right click in Ubuntu...) to a folder and link to it while compiling:
g++ hello_world.cpp -I boost_1_49_0/boost
where the last one specify the path for compiler to find the boost headers (please use absolute path).
If you want to send your program to others, dont copy only some boost files, it does not work because of the dependence. Ask them to install the same environment as you while is easy (just unzip a file...).
I don't know about your specific IDE, or about Boost.Asio specifically, but in general:
Whenever you need to link to a library, there is a file named similar to lib???.a, which you need. You need to pass the -l??? flag to g++ to link to the file.
(I'm not too familiar with the details myself, so there might be other file formats and whatnot too...)
Regarding the edit:
The "right" way would be to just have them download the library themselves, and just pass -l??? to their linker. Including Boost in your source code will make it huge, and for no good reason... it's not like you include the STL in your code, after all.
You don't include the library, but instead you declare a dependency on it. Eg. consider you use autoconf and automake then you would add AX_BOOST_BASE1 to require boost and AX_BOOST_ASIO to require the ASIO libraries. In your Makefile.am file(s) you use BOOST_CPPFLAGS and BOOST_LDFLAGS macros and rely on the ./configure to set them properly. Then whoever consumes your code will have to run the well know ./configure script which will analyze the environment for the location of boost and setup appropriate values in the build environment so that the make succeeds.
Well at least this is the theory. In practice there is a reason the whole thing is better known as autohell. Alternatives exists, like CMake or boost's own bjam. But the synopsis is always the same: you declare the dependency in your build configuration and the destination location that consumes you product has to satisfy the requirement (meaning it has to download/install the required version of boost, in your case). Otherwise you enter into the business of distributing binaries and this is frowned with problems due to richness of platforms/architectures/distributions your application is expected to be deployed in.
Obviously if you use a different build system, like ANT, then you should refer to that build system documentation on how to declare the requirement for boost.
1: ax_boost.m4 is not the only boost detecting m4 library, there are other out there, but is the one documented on the GNU autoconf list of macros

Resources