I know that clang can compile C++ files as .mm, but CImg comes as just an individual .h file. Regardless if I change the extension to .mm or keep it as .h, it doesn't work.
First, it complains that it can't find cstdio.h. As a result, I changed all the cstd.. imports to their c counterpart as a
// Include standard C++ headers.
// This is the minimal set of required headers to make CImg-based codes compile.
#include <stdio.h> // (was #import <cstdio>)
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <exception.h>
After bringing in the x11 library, I get past the import errors into syntax errors:
namespace cimg_library_suffixed {
Error: Unknown type name 'namespace'
Is this because I changed cstdio to stdio? I'm confused..
The solution in answer form for future reference:
Compile the file the header is #included from as Obj-C++ and the header will get treated as C++ code.
Related
I am building an FFI crate (the sys crate part specifically), and for the most part it's a c library with a single cpp file in it. Looks like it's some sort of vendor file.
svm.cpp links to the following standard library headers
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <float.h>
#include <string.h>
#include <stdarg.h>
#include <limits.h>
#include <locale.h>
#include <thread>
#include <fstream>
#include <sstream>
#include <vector>
Strangely, this cpp file doesn't seem to link to the c++ standard libraries that it depends on, so I had to do it through the rust build system.
previously I was able to get this working by adding the following line to my build.rs
println!("cargo:rustc-flags=-l dylib=stdc++");
This works on linux using the gnu toolchain, but i'm trying to get this to work on windows using the msvc toolchain.
So the problem is that stdc++ isn't a standardized header, and isn't included in msvc. How can I link directly to each of these c++ standard library headers instead of using stdc++?
I already tried the naive approach of just trying to link to math like so
println!("cargo:rustc-flags=-l dylib=math");
which did not yield any results
I'm using mongoose to build an HTTP server in C++, and I'm getting an error message when I try to include other files in my program:
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdint:183:8: error:
expected unqualified-id
using::intptr_t;
^
/Users/cs/Downloads/mongoose-master/mongoose.c:2415:18: note:
expanded from
macro 'intptr_t'
#define intptr_t long
^
This happens whenever I attempt include the following files in my program:
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <iterator>
#include <sstream>
I've tried to narrow it down to one of these files causing the problem by commenting out some of them, but it appears that any one of them causes the error. Interestingly enough, string.h does not cause the error.
It sounds like your source code contains something like this:
#include <mongoose.c>
The .c file defines a macro that collides with words used in the standard library headers.
Including a .c file is not a good practice. Instead, you should build the mongoose library, and link your program against it.
If you really have to keep everything in a single translation unit, you should be able to move that dubious include statement to after all other headers, or even to the bottom of your cpp file.
But it would be best to figure out how to build mongoose.c separately, then link against the resulting library. You can ask a separate question, or see if you get anything out of this: Can't figure out how to build C application after adding Mongoose Embedded
I am trying to build some code written in C++ for getting an image via Kinect and I get the following error:
You must include nuiapi.h rather than including nuisensor.h directly.
but I already included windows.h and NUIAPI.h... windows.h was included before nuiapi.h in the source file. Can anyone tell me what is wrong?
here is the code in my source file .cpp
#include <Windows.h>
#include "Kinect.h"
#include <NuiApi.h>
#include <NuiImageCamera.h>
#include <NuiSensor.h>
kinectcamera::~Kinectcamera()
{
SafeRelease<IMediaObject>(&pDMO);
SafeRelease<INuiAudioBeam>(&pAudio);
I've created an Allegro 5 project in Xcode 4.6.3 as an empty project. I've added all the Allegro 5 libraries as described in the Allegro documentation. But now I need to use some C/C++ libraries and get the error, that Xcode doesn't find the libraries (e.g. 'fstream file not found').
#include <allegro5/allegro5.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
How can I add the standard libraries to Xcode projects so that it finds them? Unfortunatelly I can't find any solution. This is not an Objective-C Project. It's written in C++ and also works if I don't use any of these libraries.
Thanks!
Does the name of your source file end with an extension that indicates it's C++? If it ends in (for instance) .c or .m, the compiler will not consider it to be C++, therefore the C++ headers won't be found. Try changing the extension on the source file name to .cpp (or some other extension that implies C++, see C++ code file extension? .cc vs .cpp ) and see if the header is found.
I got a fatal error that the file or directory <stdlib> is not found on ubuntu 11.xx when I typed #include <stdlib>.
Is <stdlib> deprecated/removed, or is there something wrong with my GCC installation?
In C++ code, include 'cstdlib' instead.
#include <cstdlib>
If you are using C, include 'stdlib.h'
#include <stdlib.h>
In c++ code, always prefer the cXXX include instead of XXX.h
Presumably you are attempting to include the C standard library header stdlib.h.
Thing is, in C++, the old C headers x.h are deprecated; you should not use them. Fortunately, C++ allows you to use C++ versions of them:
#include <cstdlib>
It's pretty much the same thing, but wrapped into the std:: namespace ... and not deprecated.
Anyway, you got your error because there's certainly no standard header named just stdlib.