Using Xcode 6 or 7 on OS X Yosemite (fully patched), I have this line at file scope:
static const vector<uint8_t>addresses = vector<uint8_t>({0x10, 0x12, 0x73});
It compiles and executes fine as part of a cpp file. When I then create a makefile and try to build, I get 'error: expected expression' pointing at the left brace. I've played around with various syntax forms, and nothing works although the errors change. I've tried both g++ and clang as the compiler, to no effect.
Can anyone please suggest why this compiles and runs with Xcode, but not with a simple make? Better yet, what is it about the syntax I'm using that's not what it should be?
I've tried various language dialects as compiler options, but otherwise the makefile is purely using defaults.
Related
I'm trying to run the example "Scale_Space_Surface_Reconstruction_3" from CGAL library on CodeBlocks IDE on Ubuntu platform, as it would be nice
to have the IDE support for code completion and a more automatic configuration process.
I managed to successfully execute it by compiling it with cmake on the terminal window.
However, on CodeBlocks, after creating a new project and copying the code from the example, I get the following error:
/usr/local/include/CGAL/Scale_Space_Reconstruction_3/Scale_Space_Surface_Reconstruction_Impl_3.h:165:23: error: variable or field 'pca' declared void
Approximation pca( _nn[i]);
By looking inside the code, I found out that this is due to an undefined Macro CGAL_EIGEN3_ENABLED. As my experiment shows, if I define the macro at
pre-processing time, I do not get the same error. That is because, by defining the macro, the type definition Default::Get< wA,void>::type, becomes
Default::Get< wA, Weighted_PCA_approximation_3<Gt>>::type, and the compiler does not complain any more.
Unfortunately, as a deserved prize for messing with things I do not really understand, I get a segmentation fault at runtime.
How should I change the compiler options of codeBlocks to make the compilation succeed, and the executable run successfully?
I have the following include paths:
/usr/local/lib/CGAL/ /usr/local/include /usr/include /usr/include/eigen3.
I also included the following libraries:
libCGAL.so, libCGAL_Core.so, libCGAL_ImageIO.so, libgmp.so, libmpfr.so, libtbb.so, libtbbmalloc.so, libtbbmalloc_proxy.so
My program compiles fine, but Netbeans tells me "Unable to resolve identifier to_string."
I tried everything in "Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful" and I set the "C++ standard" to "C++11" in the code assistance options.
This is the only function giving this problem so far. It is however also the first C++11 feature I am using, which leads me to believe it has something to do with Netbeans not understanding that I am using C++11, although I specify it explicitly in the code assistance menu.
Minimal example:
#include <string>
int main() {
std::to_string(1);
}
EDIT: the same problem arises where using nullptr
EDIT2: I suddenly realized it might be important to mention that I do not use a generated Makefile, but SCons.
I know this question is seven months old but since it came up as the second result to a google search I'll tell the answer I came up with. For Netbeans at least. Go to your project properties and make sure you have you "C Compiler"->"C Standard" set to C11, and your "C++ compiler"->"C++ Standard" set to C++11. You have to set BOTH or it will still give false errors!
This will solve the problem:
Right click on "Project".
Select "Code Assistance".
Clean C/C++ cache.
Restart IDE.
Autocomplete and sometimes even syntax highlighting are always faulty with C++. The more you go in depth with C++ and C++11, the more Eclipse and Netbeans will start underlining everything with a red wavy line. Some of my (correct and perfectly compiling) programs are a huge red wavy line. I suggest you disable error markers altogether and you keep autocomplete, but in many cases it just won't work and you have to make the best of it.
I had the same situation. This was occurred because I used .c file instead of .cpp
for Netbeans 8.2 (on Linux) only the following worked for me: Tools -> Options -> Code Assistance -> Macro Definitions:
change:__cplusplus=199711L
to:__cplusplus=201402L
for C++14
or to __cplusplus=201103L
for C++11
I did all the above but what did the trick for me was recognizing that the Makefile had g++ rather than g++ -std=c++11.
To resolve c++17 related 'Unable to resolve identifier' in latest netbeans 8.2 or 9 version, one may need to set the macro definition __cplusplus=201703L as the default C++14 standard macro definition unable to resolve those unexpected error messages appeared in the editor.
How can my program compile successfully but eclipse shows me "Semantic Errors" and how could I get rid of those errors?
The error messages I have are the following
Method 'c_str' could not be resolved (this happens also for compare and size on strings)
Here an example:
std::string someotherstring = "test";
std::string name = someotherstring.c_str();
The problem here is that it also creates follow up errors which seem all to be not true, my software compiles and runs as intended and even uses the "c_str()" returns to process messages. It seems only to be a display issue in Eclipse.
I have searched now for hours, tried to use a custom indexer but for some reason it won't go away. Maybe someone else has a good idea what to do here as Google spits out nothing about this specific problem. (I have even tried to use different C++11 standard flags as I thought it might had an impact)
I had the same problem. Solved by simply run a index -> rebuild. You can find that by clicking on the project main folder with the right button.
Cheers
If you're building your projects using mingw and using C++11, you can not use the default dialect option of -std=c++0x.
Click on 'GCC C++ Compiler' and in the Command: textbox, enter -std=gnu++0x after the g++
I have a compiling Problem using "code::blocks" on Windows 7. My C-code is:
//whatever
int main(void){return 0;}
//this is blank line
The MinGW commandline is:
gcc.exe -Wall -g -ansi -c C:...\Test\main.c -o obj\Debug\main.o
If i try to compile this, I get the error:
C:\...\Test\main.c|1|error: expected identifier or '(' before '/' token
(I wanted to post a picture here, but not enough reputation ...)
There are only 3 lines of code in my source file. (The last just contains \0, but I didn't know, how to add a blank line). I use code::blocks as IDE. I used notepad++ to search for non-printable chars, but with no meaningful results. I use the MinGW compiler that is available as bundled download with code::blocks. I corrected the "toolchain executables" and the compiler worked fine until now.
It's not the first time I had this problem. I remember having it on another computer before and solved it by retyping the whole source file (which I don't want to do every time).
The way the error was provoked is just commenting and uncommenting code for a while (I tried out some things and commented previous tests away). And than, out of the blue, this error appeared.
Sorry, if my grammar is bad. English is not my mother tongue.
I appreciate any given help!
Thanks in advance,
Nils
Remove the compiler option -ansi.
ANSI C does not understand //.
From the gcc documentation:
3.4 Options Controlling C Dialect
[...]
-ansi
In C mode, this is equivalent to -std=c90. In C++ mode, it is equivalent to -std=c++98.
[...] For the C compiler, it disables recognition of C++ style ‘//’ comments [...]
In code blocks do this
Make sure that highlighted option is unchecked.(This is same as above ans. removing -ansi. option.)
Settings->compiler
For compiling c use
/* C-style comments!
*/
I'm attempting to compile my (very basic) program that uses armadillo in XCode 4, but it is having problems with compiling armadillo.
When I do just a simple makefile and clang++, it compiles without problems, but using XCode it seems to be having serious issues, popping up with all kinds of errors and warnings, (when I build it without XCode, even using -Werrors, I get nothing, it builds clean).
Here are some of there errors:
const int __ret = std::vsnprintf(__out, __size, __fmt, __args); <-- no member named vsnprintf in namespace std (in file c++locale.h)
return (std::isfinite(x) != 0); <-- Expected unqualified-id (in file cmath_wrap.hpp)
etc. I think most of them are related to some function not in the standard library... does XCode use a different or incomplete standard library? And how do I change that.
I really just want to use the XCode debugger, it makes things easier when my code isn't running, and it is nice to have a graphical profiler as well.
Try uncheck option "recursive" in your "Build Setting/Header Search Path"