Boost / Netbeans: Recursive Includes Related to BSD on Linux Mint 17.2 - c++

I have a C++ project in Netbeans on my Linux Mint 17.2 machine. I'm using the GCC 5 toolchain (e.g. g++ 5.3.0), Netbeans 8.1, and Boost 1.61.0.
I'm encountering a weird warning in my project that shows up all over the place. For instance, in my main.cpp, I #include <iostream> at the very top, and that line gets a warning. (I see this warning happen for the first file I include in every file, so it is not an issue with iostream etc.).
The warning is that there is a recursive #include in boost. Specifically, Netbeans complains that <boost/predef/os/bsd/free.h> includes <boost/predef/os/bsd.h> and that <boost/predef/os/bsd.h> includes <boost/predef/os/bsd/free.h>. For the record, this appears to be true - does anyone know why there is this recursive include in boost, and if it is really supposed to be there?
The bigger issue is that my system is not BSD, so I don't know why I'm getting these warnings from the BSD headers, which shouldn't be included or active/defined. I tried printing BOOST_PLATFORM_CONFIG from my main.cpp, and it prints out the path to boost's Linux config header, as expected - not the BSD config header. And, my program compiles and runs fine, so I'm assuming it's never actually using the BSD headers. Which means that the fact that these BSD headers are giving me warnings might be a Netbeans problem, not a boost problem.
Does anyone have any ideas on how to narrow down and fix this issue with these strange recursive include warnings?

I was having the same problem. The issue is with the boost predef/os/bsd.h header. It #includes 5 files in the #else block for the #ifndef BOOST_PREDEF_OS_BSD_H guard. This means that this header file is not guarded against recursion if any of those 5 files also includes bsd.h (which they do).
My solution was to edit the predef/os/bsd.h file and add a recursion guard in the #else block - so, starting at around line 94 my predef/os/bsd.h file now looks like:
#ifndef BOOST_PREDEF_OS_BSD_H_PREVENT_RECURSION <-- ADD THIS
#define BOOST_PREDEF_OS_BSD_H_PREVENT_RECURSION <-- ADD THIS
#include <boost/predef/os/bsd/bsdi.h>
#include <boost/predef/os/bsd/dragonfly.h>
#include <boost/predef/os/bsd/free.h>
#include <boost/predef/os/bsd/open.h>
#include <boost/predef/os/bsd/net.h>
#endif <-- ADD THIS
And now netbeans code assistance is happy and my code still links and compiles without error.

The rough way: comment
#include <boost/predef/os/bsd.h>
Everywhere (should be inside the following headers)
predef/os.h
predef/other/endian.h

Related

Xcode 11.1: iostream' file not found

I just updated my MacBook Pro to macOS Catalina 10.15, and tried to compile and run a C++ command line program, but I had a problem which didn’t exist on previous versions;
This is simply the code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!\n";
return 0;
}
The code compiles and outputs the expected, but still the Xcode says:
fatal error: 'iostream' file not found
I tried changing the Build Settings/C++ Standard Library to libstdc++, but a warning says:
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead
And the same iostream error still exists.
I'm compiling from the command line, and none of the answers listed here (or elsewhere) worked for me.
What does seem to work (so far) is to add the following to .profile or whatever script your terminal uses to start up: (zsh, csh, bash, etc.)
export C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include
export CPLUS_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include
You will probably have to change MacOSX10.15.sdk whenever you upgrade your operating system.
C_INCLUDE_PATH and CPLUS_INCLUDE_PATH are options for the clang toolchain rather than MacOS environment, so hopefully this solution will work long-term, unlike xcode-select --install (which won't fix the include directories on an upgrade) or ln -s ... /usr/include (which is now forbidden by System Integrity Protection).
I had the same problem and used the following youtube video to fix it.
https://www.youtube.com/watch?v=hrPm7tWC-BI&feature=youtu.be
or you can follow this path. Make sure to include the quotation marks
Project - Build Settings - Search Paths - Headers Search Paths, and add the following path:
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/"
So, I restarted my laptop and everything seems to be fine right now, thanks for those who tried to help.
libstdc++ is not OK for Xcode Build & Compile time,
libstdc++ is OK for iPhone Run Time
From answer recommended by #Alan Birtles
libstdc++ Support was removed from the iOS 12.0 Simulator runtime, but
it remains in the iOS 12.0 (device) runtime for binary compatibility
with shipping apps.
I encountered this when declaration in .hpp file.
#include <iostream>
#include <string>
OK with
#ifdef __cplusplus
#include <iostream>
#include <string>
// usage code
#endif
I tried a fresh Catalina install with Xcode. I copied and pasted your code into "test.cpp" and then ran:
clang++ test.cpp
in the same directory as the "test.cpp" file from Terminal. The result was an "a.out" file which when run:
./a.out
output the required "Hello, World!" result. Hopefully that is of some use (as a point of reference).

CLion doesn't resolve headers from external library

Some time ago I started a big header library in C++1x using XCode. The current layout of the library is () something like (partial output from ls -R sponf)
sponf/sponf:
ancestors sponf.h sponf_utilities.h
categories sponf_children.h utilities
children sponf_macros.h
sponf/sponf/ancestors:
function.h meter.h set.h simulation.h
sponf/sponf/categories:
free_space.h prng.h random_distribution.h series.h
sponf/sponf/children:
distributions histogram.h random simulations
meters numeric series spaces
sponf/sponf/children/distributions:
arcsine_der.h exponential.h
box_muller.h uniform.h
sponf/sponf/children/meters:
accumulator.h timer.h
#... other subdirs of 'children' ...
sponf/sponf/utilities:
common_math.h limits.h string_const.h
#... other directories ...
I wanted to port this project to CLion, which seems a really good IDE (based on the similar AndroidStudio IDE) but I'm getting some troubles.
Small test program
I tried this small program as a test:
#include <iostream>
#include <sponf/sponf.h>
using namespace std;
int main() {
using space = sponf::spaces::euclidean_free_space<double, 3>;
sponf::simulations::random_walk<space> rw;
rw.step(1);
std::cout << rw.position.value << std::endl;
return 0;
}
The program compiles and runs fine. However, CLion does not recognize the spaces namespace (declared in one of the children files), nor the simulations namespace; they are both marked red and I cannot inspect their content, nor navigate to their definitions by ⌘-clicking, etc. etc...
Relevant parts of the library
Looking in "sponf.h" we find
#ifndef sponf_h
#define sponf_h
/* The classes below are exported */
#pragma GCC visibility push(default)
// include some of the standard library files
// ...
#include <Eigen/Eigen>
#include "sponf_macros.h"
#include "sponf_utilities.h"
#include "sponf_children.h"
#pragma GCC visibility pop
#endif
while in "sponf_children.h" (which is located at the top level, next to "sponf.h") we find
#ifndef sponf_locp_sponf_children_h
#define sponf_locp_sponf_children_h
namespace sponf {
// include some of the children
// ...
#include "children/spaces/euclidean_free_space.h"
#include "children/simulations/random_walk.h"
// include remaining children
// ...
}
#endif
Each "child" header will then include its corresponding "ancestor" or "category" header (which defines the superclass of the "child" itself).
The reaction of CLion
Despite the autocompletition prediction, which easily finds all the subdirectories and the headers, all the include directives in this last file get marked red and ⌘-clicking on any of them leads to a popup message
Cannot find declaration to go to
while the right ribbon of the editor signal many errors like
',' or ) expected
) expected
Declarator expected
Expecting type
Missing ;
Unexpected symbol
which are not the same for each include statement (each generates from 2 to all of these errors).
On the other hand, CLion is perfectly able to find all Eigen headers, which have pretty much the same structure!
I have put both libs in /opt/local/include and changed CMakeLists.txt accordingly
cmake_minimum_required(VERSION 2.8.4)
project(sponf)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
include_directories(/opt/local/include/sponf /opt/local/include/eigen3)
set(SOURCE_FILES main.cpp)
add_executable(sponf ${SOURCE_FILES})
Why can't CLion properly parse the project structure? XCode, after having included /opt/local/include/sponf and /opt/local/include/eigen3 in the HEADER_SEARCH_PATHS env. variable of the project, is able to find any header while compiling the same exact program.
Is there anything else I need to know? Am I doing it wrong or is it that CLion isn't that mature yet and this is just a sorry bug? This is my first approach to the CLion and the CMake toolchain, so any kind of information about it will be greatly appreciated!
Sorry for the very long question, I didn't manage to shrink it further... Thanks in advance guys, see you soon!
Here what I did in windows using cigwin64. I wanted to use Eigen library include in my project.
Eigen library is places in /usr/include/eigen then edited CMakeLists.txt and add
include_directories("/usr/include/eigen")
into it. Now CLion can find all source files in eigen lib. May be this what you wanted too.
Downgrade to Clion 2016.1.4 fixes the problem

Code-sense in embedXcode doesn't hightlight syntax for the library I've included

Code-sense mostly works-- all of the core Arduino types are hightlighted properly. But no types
referencing the FastLED library are.
My code compiles fine. And, syntax is hightlighted properly in FastLED.h
How can I make use of code-sense in xCode for Arduino libraries?
At the top of my .ino file, I do this
// Core library for code-sense
#include "Wiring.h"
#include "Arduino.h"
// Include application, user and local libraries
#include "LocalLibrary.h"
#include "FastLED.h"
I am running XCode 5.1 on OSX 10.9.2 with embedXcode+ (professional) release 136. I checked out the FastLED_2.1 branch, as master does not support Teensy 3.1, the board I am using.
Solved. It appears that NO libraries listed in USER_LIBS_LIST confer the benefits to code-sense to your main ino file. However, once I moved the FastLED from
/Users/justin/Documents/Arduino/Libraries
to
/Applications/Arduino.app/Contents/Resources/Java/libraries
and restarted XCode, everything works great.
It seems the table for libraries reached an overflow.
WARNING Overflow reached

Use of #include <iostream.h>

I am working on an older project that still has the deprecated "#include iostream.h" inclusions. I understand that iostream.h is deprecated and should not be used, but some of the systems that this code has to run/compile on are old solaris machines running CC and do not have iostream available. My question is: how can I make my more modern g++ compiler accept the iostream.h inclusions.
EDIT: The compilier cannot find the iostream.h file so I am assuming that none of the .h versions of the library are available to g++.
The easiest solution is probably to create a local header file called iostream.h which just includes <iostream> and imports the namespace std. Then, in order for the compiler to allow #include <iostream.h> you add the local path to your include file search path. For g++, this works:
g++ -I local_folder [other flags] …
Incidentally, your remark about
… the deprecated "#include iostream.h"
isn’t quite correct: this isn’t deprecated because it has never been legal C++.
I'd take a step back and write another intermediate header you use everywhere instead that does something like:
#if defined(sun) || defined(__sun)
# if defined(__SVR4) || defined(__svr4__)
/* Solaris */
#include <iostream>
# else
/* SunOS */
#include "iostream.h"
# endif
#else
/* Sane, modern system */
#include <iostream>
#endif

compiling a C++ class in Xcode: error during compilation: stl vector

I have a C++ class that compiles fine on linux with gcc and on widows in visual studio.
boid.h:
#ifndef BOID_CLASS_HEADER_DEFINES_H
#define BOID_CLASS_HEADER_DEFINES_H
#include "defines.h"
class Boid {
public:
// Initialize the boid with random position, heading direction and color
Boid(float SceneRadius,float NormalVel);
.....
protected:
...
};
#endif
and in boid.cpp:
#include "Boid.h"
// Initialize the boid with random position, heading direction and color
Boid::Boid(float SceneRadius,float NormalVel)
{
....
}
However, I get the following error when I compile this code in Xcode:
Compiling Boid.h: "error: vector: No such file or directory"
Any ideas? I thought you could take C/C++ code and compile it in Xcode without issues?
Thanks
EDIT: Added defines.h (also added #endif to sample, but that was in the original code)
EDIT 2: I am getting a different error after a commenting out a couple of includes there were empty: the vector error above.
#ifndef BOID_NAV_DEFINES_H
#define BOID_NAV_DEFINES_H
#include <stdlib.h>
#include <vector>
#include "Vector3d.h"
#include "Point3d.h"
#include "win_layer.h"
#endif
Are you including the C++ header in a .m file?
.m files are treated as .c files with Objective-C extensions.
.mm files are treated as .cpp files with Objective-C extensions, then it's called Objective-C++
Just rename any .m file to .mm, right-click or ctrl-click and select rename on the file in Xcode.
Without changing any .m to .mm or anything like that, if you click your project, click tagets->build settings
go all the way down to "LLVM GCC 4.2 - Languages" (new xcode says "Apple LLVM compiler 4.2") you will see Compile Sources As change that value to Objective-C++;
I hope this will help.
After updating xCode to version 10, I have had issues including < map > and < vector > libraries. Found an easy solution by changing the C++ library type in the project's build settings (target's Build Settings):
C++ Standard Library: libc++ (LLVM C++ standard library with C++ 11 support)
Compiled without any problem.
Make sure you're compiling it as C++. Right click the file in XCode and select Get Info and make sure that File Type is set to sourcecode.cpp.cpp for the implementation files.
Assuming you're talking about the OS X XCode, that uses gcc to do the actual compiling. So there should be no difference between that and Linux, other than maybe different versions of gcc.
First thing that jumps out at me here is that you've typed "boid.h" as the name of the file, but you're including "Boid.h". Assuming that's not a typo, I would expect that to cause trouble on both Linux and OS X....
Edited to answer the new question: Hmmm... vector is definitely part of Xcode: /Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.0.0/vector on my machine.
Further thought: If you port the source and makefiles from the Linux build over to the Mac, you can probably just compile it from the command line exactly like you do on Linux....
Definitely, something in defines.h is affecting the class definition.
This issue had two errors:
one of my includes had a typo which caused a compile error
the vector not found error was fixed by the .m files to .mm
Not sure if you forgot to paste, but you have an unterminated #ifndef
What's inside defines.h ?
Edit: You seem to have found the solution. One more remark:
#include <stdlib.h>
For C++, please:
#include <cstdlib>
:D