Trying to compile an open source project with both VS2010, VS2012 in x86 and x86_64 on a windows platform running QT5.4.
A file named unit.h contains a part :
[...]
// DO NOT change noscale's value. Lots of assumptions are made based on this
// value, both in the code and (more importantly) in the database.
enum unitScale
{
noScale = -1,
extrasmall = 0,
small = 1, // Line that causes errors.
medium = 2,
large = 3,
extralarge = 4,
huge = 5,
without = 1000
};
[...]
Generates
error C2062: type 'char' unexpected
error C3805: 'type': unexpected token, expected either '}' or a ','
I tried every trick in my hat to solve it. I removed every use of the "small" enum in the code and I still get the error. But after having removed all the uses, I rename "small" to "smallo" everything is fine. It seems to indicate name collision but a file search gives me no references in the whole project. It's not any keyword I know of.
Got any ideas?
EDIT: Thanks to very helpful comments here is an even stranger version that works. Could somebody explain?
#ifdef small // Same with just straight "#if"
#pragma message("yes")
#endif
#ifndef small
#pragma message("no") // Always prints no.
#endif
#undef small
enum unitScale
{
noScale = -1,
extrasmall = 0,
small = 1,
medium = 2,
large = 3,
extralarge = 4,
huge = 5,
without = 1000
};
EDIT 2: The pragma directive was showing yes but only in files that had previously loaded the windows.h header, and it was lost in the compiler output in a sea of no.
Thanks everyone! What a quest.
small is a defined in rpcndr.h. It is used as datatype for MIDL.
Related
I've been at this for hours now.
I compile a stan model with the following code:
model <- stan(file = "model.stan", data = data, save_dso = FALSE, chains = 4, cores = 4, iter = 2000, warmup = 1000)
When I ls the current directory, I see model.rds whereas I didn't see it before. All is good thus far.
Subsequently, I refit this model with new parameters via:
fit <- stan(file = "model.stan", data = new.data, chains = 1, cores = 1, iter = 4000, warmup = 2000)
This code is running in a Shiny app. Locally, all works as expected.
When I deploy this app to shinyapps.io, the model tries to recompile (resulting in a g++ error - presumably from lack of sufficient memory). Irrespective, I don't want this model to recompile in the first place: I'd like it to use the model.rds object I'd already built. Yes, I do include this object in the files uploaded to the shinyapps.io server.
I feel like I've tried all the things - including loading model.rds explicitly with loadRDS and passing it into the stan(fit = model ... call. What am I missing?
For completeness, below is the error I received on the shinyapps.io end. Again, I don't wish for this model to go about recompiling in the first place.
Compilation ERROR, function(s)/method(s) not created! In file included from /usr/local/lib/R/site-library/BH/include/boost/config.hpp:39:0,
from /usr/local/lib/R/site-library/BH/include/boost/math/tools/config.hpp:13,
from /usr/local/lib/R/site-library/StanHeaders/include/stan/math/rev/core/var.hpp:7,
from /usr/local/lib/R/site-library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5,
from /usr/local/lib/R/site-library/StanHeaders/include/stan/math/rev/core.hpp:12,
from /usr/local/lib/R/site-library/StanHeaders/include/stan/math/rev/mat.hpp:4,
from /usr/local/lib/R/site-library/StanHeaders/include/stan/math.hpp:4,
from /usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from file137729fa09.cpp:8:
/usr/local/lib/R/site-library/BH/include/boost/config/compiler/gcc.hpp:186:0: warning: "BOOST_NO_CXX11_RVALUE_REFERENCES" redefined [enabled by default]
# define BOOST_NO_CXX11_RVALUE_REFERENCES
^
<command-line>:0:0: note: this is the location of the previous definition
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.8/README.Bugs> for instructions.
make: *** [file137729fa09.o] Error 4
I am a novice c++ programmer so please forgive me if this is a naive question. I have files containing large arrays holding tens-of-thousands of strings that I have used previously in javascript applications. Is there some way to include these into C++ source code so that the arrays are compiled along with the code?
At present, the files are formatted as functions that return (javascript) literal arrays, like this:
// javascript array stored in .js text file
function returnMyArray()
{
return ["string1", "string2", "string3", ... "stringBigNumber"];
} // eof returnMyArray()
I 'include' the external file with the usual javascript script & src tags and assign the array with something like:
myArray = returnMyArray();
I want to achieve the equivalent in c++, i.e. assign an array stored in a file to an array in my c++ source code so that the data is available for execution when compiled.
I suppose in theory I could copy and paste (suitable formatted) arrays from files into my c++ source code but they are too large for this to be practical.
I can easily re-write the files to whatever format would be easiest to have c++ access the data - either in c++ array syntax or one string per line to be read into an array.
In a similar vein, is there an easy way to include files containing custom function libraries when compiling with g++ in terminal? (my web searches show plenty of ways for various IDE applications but I am writing source in vim and compiling with g++ on the command line).
I am sorry if this is trivial and I have missed it but I am stumped!
Thank you.
Here's how I'd structure this:
file: data.array
/* C++ style comments are ok in this file and will be ignored
* both single and multiline comments will work */
// the data in the array is a comma seperated list, lines can be any length
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
// more comma seperated data
9996, 9997, 9998, 9999
file: class.h
extern int myArray[]; // you should fill in the size if you can
// more stuff here
file: class.cpp
// if you have an editor that highlights syntax and errors, it may not like this
// however, #include is handled before compiling and performs a blind substitution
// so this is perfectly legal and should compile.
// Visual C++ 2010 highlights this as an error, but the project builds fine.
int myArray[]
{
#include "data.array"
};
// other definitions of stuff in class.h
As part of a bigger project ( the ff activex plugin for Mozilla Firefox) there is this code snippet:
if (CombineRgn(hrgnClip, hrgnClip, hRGN, RGN_AND) != ERROR)
{
::InvalidateRgn(m_hWndParent, hrgnClip, fErase);
}
When I build in VS2012 I get "Error C2065: 'ERROR' : undeclared identifier"
ERROR is defined in wingdi.h like this:
...
/* Region Flags */
#define ERROR 0 // it wont build when this macro is used
#define NULLREGION 1 // it builds when this macro is used
#define SIMPLEREGION 2
#define COMPLEXREGION 3
#define RGN_ERROR ERROR
...
The strange thing is that if I replace ERROR (just to see if it builds OK) with NULLREGION or SIMPLEREGION (which are macros in the same file, just two lines below the offending one) in the if statement above, the code builds OK. When I use ERROR, the code wont build.
Is it possible that the ERROR macro defined above gets masked by some keyword or another macro or some such by Visual Studio?
The problem here is that ERROR actually appears in the compile error message. That should not happen, the preprocessor should have substituted it with 0.
So somewhere in a .h file you #included after windows.h, some programmer took the 10 second shortcut to a macro name collision problem and wrote this:
#undef ERROR
You'd need to find that line and remove it. That's likely to be difficult and liable to give you a maintenance headache since that's a file you don't own and might well be updated in the future, forcing you to make that change over and over again. The alternative is to redefine it yourself:
#define MYGDIERROR 0
...
if (CombineRgn(hrgnClip, hrgnClip, hRGN, RGN_AND) != MYGDIERROR)
//etc...
Which still gives you a maintenance problem and requires you taking a bet that the return value definition of CombineRgn() is never going to change. That's a very safe bet, GDI is cast in stone.
I have been using the allegro 5 libraries for developing a game in C++ for some time. Today I got some weird error:
I have a class called level. I have a header file called levelhandler.
Here's how it looks:
#pragma once
#include "level.h"
level level_1;
level *currentlevel;
void initialize_levels()
{
currentlevel = &level_1;
}
When I try to compile it gives me strange errors like:
error C2086: 'int level' redefinition
error C2143: syntax error : missing ; before 'level_1'
I remember that it could compile before, and I did use currentlevel->Player.X a lot of times, but now I have a lot of that and it gives errors like these:
error C2227: left of '->Player' must point to a class/struct/generic type
error C4430: missing type specifier - int assumed
header pasted from comment
#pragma once
#include "entity.h"
// some more includes
class level {
public:
enum Tileset { ... };
enum Tile { ... };
int tiles[200][200];
player Player;
level(void);
~level(void);
};
Such errors are hard to find as long as you look at the "Error List" pane. Select View/Output to show the "Output" view. The line after the error C2086 shows the original definition of level.
You fill find an
int level;
there as the C2086 tells you. If it's the line
level level_1;
of your fist example you will have to check the last header file include in your compilation unit. It might end with an int or it has a unbalanced #if clause.
To find the exact location start using a Short, Self Contained, Correct (Compilable), Example. This helps you to find the bug and saves time of other with their crystal balls.
Edit:
Another way to find the reason for this unexpected behavior is to see the preprocessor output. Set the Generate Preprocessed File option int the C/C++/Preprocessor project property page to With line numbers (/P) and look in the generated <sourcefile>.i
Check that that level.h file has included what you intended.
Ok, so I've been tinkering around with my project the weekend, and I finally found out what whas the problem that gave me so many weird compiler errors. It seems that I had a lot of cases where two header files were including each other, and the compiler really didn't like that, so I corrected that, and now I'm ok. Thank you all for helping me, and have a great day!
I primarily program in Java but I am taking a graphics course for which I need to use C++. I am trying to create an array of objects in order to loop through them and draw them to the screen, but I can't for the life of me figure out how to create this array. I have code now which does not produce any compiler errors, but it doesn't seem to work correctly either. The following code is at the top of my Main.cpp class:
Platform ground("wallstone.tga", 40, 16, 4, 144);
Platform platform1("wallstone.tga", 10, 16, 4, 20);
Platform platforms[2] = {ground, platform1}
When I try: fprintf(stdout, "Size of platforms array: %d", sizeof(platforms)/sizeof(Platform)); it prints out 0.0.
I've tried several ways of creating this array and they all seem to produce errors or that same output of 0.0, so I'm not sure what's going on. If any more of my code is necessary I will certainly be willing to post it. Of course, if there is a better way of approaching this I am grateful. Thanks!
It looks like you are doing everything right. My only guess is that size_t on your platform is larger than int, so providing a correct format specifier (%z instead of %d) may fix the problem:
fprintf(stdout, "Size of platforms array: %z", sizeof(platforms)/sizeof(Platform));