Compiliation error with templates using g++, compiles ok with llvm - c++

I really don't know what to make of this. I have some code that is being shared on iOS and a Linux server. The iOS LLVM compiler compiles just fine however when I try to compile on Linux with g++ I get many errors. The first one being the following:
RemoveLight.h: In member function ‘void RemoveLight<WindowDerived, ChunkDerived, dim>::lightRemoveEditStart()’:
RemoveLight.h:49:17: error: ‘FloodFillLight’ was not declared in this scope
RemoveLight.h:49:45: error: expected primary-expression before ‘,’ token
RemoveLight.h:49:59: error: expected primary-expression before ‘,’ token
This is line 49:
FloodFillLight<WindowDerived, ChunkDerived, dim>(x, i, z, target, chunkWindow);
I do have FloodFillLight.h included in RemoveLight.h so that isn't the problem and my templates are all declared in a .h file. I don't have any part of the templates defined in a cpp file. Anyone have ideas?

Try preprocessing the file and make sure that FloodFillLight is declared before it's used.
It might be that a stray #ifdef is muddling up your includes.

Related

G++ not finding symbols from regex system header

I am trying to use the GNU C library regex functionality in my C++ project, particularly I'm trying to use the regex_t regcomp, regexec, regfree functions. Upon compilation I get errors stating that these symbols are undefined:
me> g++ -I/me/myheaders/ -c RootGenerator.cpp -o RootGenerator.o -std=gnu++0x -Wall
RootGenerator.cpp: In function ‘std::string findFirstFileInCurrentDirectory(std::string)’:
RootGenerator.cpp:1072: error: ‘regex_t’ was not declared in this scope
RootGenerator.cpp:1072: error: expected ‘;’ before ‘re’
RootGenerator.cpp:1073: error: ‘re’ was not declared in this scope
RootGenerator.cpp:1073: error: ‘REG_EXTENDED’ was not declared in this scope
RootGenerator.cpp:1073: error: ‘REG_NOSUB’ was not declared in this scope
RootGenerator.cpp:1073: error: ‘regcomp’ was not declared in this scope
RootGenerator.cpp:1074: error: expected ‘;’ before ‘int’
RootGenerator.cpp:1084: error: ‘status’ was not declared in this scope
RootGenerator.cpp:1084: error: ‘regexec’ was not declared in this scope
RootGenerator.cpp:1092: error: ‘REG_NOMATCH’ was not declared in this scope
RootGenerator.cpp:1108: error: ‘regfree’ was not declared in this scope
I realize that the regex header is a TR1 implementation and is therefore experimental for my version of GCC. I added the -std=gnu++0x compiler option according to the compiler warning recieved when first trying to compile but this doesn't seem to fix the issue. Is this an issue of the system not recognizing and adding paths to "experimental" headers? Are there additional include paths or compiler options that I need to specify?
As an additional note, I noticed in Eclipse/CDT that under the "includes" tab in the Project Explorer view, it shows a list of the system header paths. It lists many header files under the /user/include/c++/4.4.4 path tab, but It doesn't list the regex header. I think this is also reaffirming that there is a setting issue.
Found the problem:
#include <regex>
should be
#include <regex.h>
The regex.h header is the GNU C library implementation of regex, containing the functions I was trying to use in my source. The regex header is the TR1 (and incomplete) regex implemntation. So #Oli, I wasn't referencing the relevant header after all!

How to include Accelerate framework with i686-apple-darwin11-llvm-g++-4.2?

I am trying to use the Accelerate framework on a small C++ program. I'm not even using XCode, only a simple Makefile.
The compiler complains when I add the following line to my code:
#include <Accelerate/Accelerate.h>
The error is the following:
In file included from /System/Library/Frameworks/vecLib.framework/Headers/vecLib.h:41,
from /System/Library/Frameworks/Accelerate.framework/Headers/Accelerate.h:20,
from Diana.cpp:20:
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected identifier before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected `}' before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected unqualified-id before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9028: error: expected declaration before ‘}’ token
The compiler I'm using is i686-apple-darwin11-llvm-g++-4.2, which is a gcc 4.2.1, and the line that I use to compile (not to link) is:
i686-apple-darwin11-llvm-g++-4.2 -D__MACOSX_CORE__ -c -o Diana.o Diana.cpp
Should I add some additional flag(s) when compiling this? I tried adding the "-framework Accelerate", but it doesn't change anything, since this should only be included in the linkage process (am I right?).
I googled some of these error messages and I didn't find anything.
I would really appreciate any help. Thank you!
PS: My OS X version is Lion 10.7.5, and XCode is 4.4.1.
I figured it out: I checked what was on line 9008 of vDSP.h and the problem was that I was declaring an FFT_FORWARD constant before including the Accelerate.h.
Fixed!

Getting error 'char16_t and char32_t undeclared'

I am developing a program in C++ on Linux. The gcc version is 4.5.1 20100924. I want to use std::atomic_int in my program. I have included atomic header as below:
include <atomic>
When I compile the program I get below errors:
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomic_base.h:87:0,
from /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/atomic:41,
from ../Source/Main.h:33:
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:107:25: error: ‘char16_t’ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:107:33: error: template argument 1 is invalid
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:107:53: error: invalid type in declaration before ‘;’ token
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:110:25: error: ‘char32_t’ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:110:33: error: template argument 1 is invalid
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:110:53: error: invalid type in declaration before ‘;’ token
If I include <cstdint>, I get the same errors. The headers uchar.h and cuchar.h are not there on my system. How can I resolve the compilation errors?
Thank you in advance.
EDITED:
I was wrong about that. just pass --std=c++0x to g++, and that would do it.
You seem to not have enabled C++11 support in your compiler or you use a compiler that has these new types not declared.
For char16_t and char32_t, you need no extra include.
g++ howto:
Type g++ --version. If it is at least 4.4, then it has support for new string literals. If not: You need a newer compiler version.
Then, make sure to pass --std=c++0x or --std=c++11 to the compiler.

C++ MEX compilation in MATLAB

I am trying to use a function called edfImport (available here: http://kobi.nat.uni-magdeburg.de/edfImport)
In order to use the function, I must first run edfCompile (included in the toolkit). When running edfCompile, I get an error:
??? Error using ==> mex
Unable to complete successfully
I am running MATLAB 7.1 (R14) and have the latest version of MinGW, Cygwin and Gnumex setup for my compiler (according to the instructions on this page: http://ptolemy.eecs.berkeley.edu/ptolemyII/ptII4.0/cygwin.htm)
I am able to compile example mex files, but I'm still not convinced that this isn't an issue with the way my compiler is setup. Any tips gratefully received. It would be nice to know if anyone else has trouble running edfCompile as well... (http://kobi.nat.uni-magdeburg.de/edfImport)
Many thanks
Edit: The error message in full:
In file included from edfMexImport.cpp:6:0:
EDFFile2.h:37:39: error: 'mwSize' has not been declared
EDFFile2.h:127:45: error: 'mwIndex' has not been declared
edfMexImport.cpp: In function 'void mexFunction(int, mxArray**, int, const mxArray**)':
edfMexImport.cpp:12:3: error: 'mwSize' was not declared in this scope
edfMexImport.cpp:12:10: error: expected ';' before 'OutputDims'
edfMexImport.cpp:48:12: error: expected ';' before 'OptionsDimN'
edfMexImport.cpp:49:9: error: 'OptionsDimN' was not declared in this scope
edfMexImport.cpp:51:13: error: 'OptionsDim' was not declared in this scope
edfMexImport.cpp:51:33: error: expected primary-expression before ')' token
edfMexImport.cpp:51:34: error: expected ';' before 'mxGetDimensions'
edfMexImport.cpp:73:12: error: expected ';' before 'FlagsDimN'
edfMexImport.cpp:74:9: error: 'FlagsDimN' was not declared in this scope
edfMexImport.cpp:76:13: error: 'FlagsDim' was not declared in this scope
edfMexImport.cpp:76:31: error: expected primary-expression before ')' token
edfMexImport.cpp:76:32: error: expected ';' before 'mxGetDimensions'
C:\PROGRAM FILES\MATLAB71\BIN\MEX.PL: Error: Compile of 'edfMexImport.cpp' failed.
??? Error using ==> mex
Unable to complete successfully
Error in ==> edfCompile at 15
eval(sprintf('mex -I''%s'' edfMexImport.cpp EDFFILE2.cpp ''%s/edfapi.lib''', edfapiIncludesFolder, edfapiLibraryFolder));
It looks like some type definitions are missing, particularly the mwSize and mwIndex type.
Can you add the following to EDFFile2.h and try again?
just below
#include "edf.h"
#include <mex.h>
add this:
#ifndef mwSize
#define mwSize int
#endif
#ifndef mwIndex
#define mwIndex int
#endif
The MEX file has been modified to support the 64-bit "large array handling API", as described in this document:
http://www.mathworks.com/support/solutions/en/data/1-5C27B9/
Note that this optional large variable support was first added in R7.3 (2006b), and your version is even older. Basically, your MATLAB is too old for the API used by the MEX file. That said, if the MEX file is simple enough, Gunther's solution might be the simple answer to "backport" the MEX file to your older MATLAB. Functions like mxGetDimensions() now return mwSize*, but used to return int*.
So upgrade MATLAB if you can, else try Gunther's answer and let us know how it goes.
Have you looked inside edfCompile.m? Unfortunatlly I don't have Matlab installed on my PC, so I can only suggest you to try to compile the two .cpp files edfMexImport.cpp and EDFFILE2.cpp manually with edfapi.lib

How to compile C++ files generated by google's protobuf compiler on OS X

I'm using a Mac. I have a library written in C++, let's call it "wibble", along with its source code. I can compile this source with GCC 4.3 from macports (g++-mp-4.3), and can link the resulting library into other stuff as long as I use GCC 4.3.
However, I need to link this into another application (let's call it "blort") which will only load libs compiled with the GCC 4.2 that is bundled with OS X 10.6 (because that's what it was built with)
I can, more or less, mess with wibble's Makefile however I may please, but blort is a fixed target. I can write whatever code or build scripts to glue them together I may need. There appears to be no way to get wibble to compile on 4.2 (barring a rewrite, which is out of the question), and the guy who wrote it confirms that.
I am not very familiar with the whole build and linking process in C++, having only been handed this integration, and am completely stumped. Is what I'm trying to achieve even possible? If so, how?
In case it matters, what I'm trying to do is call the methods in wibble from Perl via Inline::CPP, but I'm willing to write raw XS if I have to (I've done that before, at least). I need to use the system perl so this will easily build and install on other people's machines. :-/
UPDATE, 2012-03-01, 1
I am looking into compiling protobufs using the Mac's compiler, and seeing if I can get wibble to compile with the same compiler using that build of protobufs. I will post the results shortly.
Hrmph same errors:
g++ -Wall -Wno-unused-function -Wno-long-long -pedantic -O3 -I/Users/sscaffid/local/include -L/Users/sscaffid/local/lib -fPIC -std=c++98 -c wire.pb.cc
In file included from /Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:43,
from wire.pb.cc:10:
/Users/sscaffid/local/include/google/protobuf/wire_format_lite.h:94: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/wire_format_lite.h:117: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/wire_format_lite.h:132: error: comma at end of enumerator list
In file included from wire.pb.cc:10:
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:303: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:304: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:305: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:306: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:307: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/wire_format_lite_inl.h:308: error: extra ‘;’
In file included from wire.pb.cc:11:
/Users/sscaffid/local/include/google/protobuf/descriptor.h:322: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/descriptor.h:341: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/descriptor.h:352: error: comma at end of enumerator list
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1206: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1223: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1243: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1249: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1257: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1264: error: extra ‘;’
/Users/sscaffid/local/include/google/protobuf/descriptor.h:1274: error: extra ‘;’
In file included from wire.pb.cc:13:
/Users/sscaffid/local/include/google/protobuf/wire_format.h:226: error: comma at end of enumerator list
make: *** [wire.pb.o] Error 1
From the question:
Solution:
Using the -pedantic option to GCC 4.2 makes it very angry with protobuf code. Don't use it.