Hi I've a program written in C++. When I compile it in Mac terminal with g++ compiler, it compiles and runs. But when I compile the same C++ program in Ubuntu terminal with g++ compiler, it Fails. I don't know why it happens.
g++ compiler version in Ubuntu is 4.7.3.
Here is my code sample
#include <iostream>
using namespace std;
#define IXSIZE 400
#define IYSIZE 400
#define IZSIZE 3
void putbyte(FILE *outf, unsigned char val)
{
unsigned char buf[1];
buf[0] = val;
fwrite(buf,1,1,outf);
}
void putshort(FILE *outf, unsigned short val)
{
unsigned char buf[2];
buf[0] = (val>>8);
buf[1] = (val>>0);
fwrite(buf,2,1,outf);
}
I get following error
seperate.cpp: In function ‘void putbyte(FILE*, unsigned char)’:
seperate.cpp:23:21: error: ‘fwrite’ was not declared in this scope
seperate.cpp: In function ‘void putshort(FILE*, short unsigned int)’:
seperate.cpp:32:21: error: ‘fwrite’ was not declared in this scope
seperate.cpp: In function ‘int putlong(FILE*, long unsigned int)’:
seperate.cpp:43:28: error: ‘fwrite’ was not declared in this scope
seperate.cpp: In function ‘short unsigned int getshort(FILE*)’:
seperate.cpp:49:22: error: ‘fread’ was not declared in this scope
seperate.cpp: In function ‘long int getlong(FILE*)’:
seperate.cpp:56:22: error: ‘fread’ was not declared in this scope
seperate.cpp: In function ‘int main(int, char**)’:
seperate.cpp:88:11: error: ‘stderr’ was not declared in this scope
seperate.cpp:88:69: error: ‘fprintf’ was not declared in this scope
seperate.cpp:89:9: error: ‘exit’ was not declared in this scope
seperate.cpp:93:30: error: ‘fopen’ was not declared in this scope
seperate.cpp:95:11: error: ‘stderr’ was not declared in this scope
seperate.cpp:95:61: error: ‘fprintf’ was not declared in this scope
seperate.cpp:96:9: error: ‘exit’ was not declared in this scope
seperate.cpp:101:22: error: ‘fgetc’ was not declared in this scope
seperate.cpp:114:18: error: ‘SEEK_CUR’ was not declared in this scope
seperate.cpp:114:26: error: ‘fseek’ was not declared in this scope
seperate.cpp:126:38: error: ‘fread’ was not declared in this scope
seperate.cpp:131:12: error: ‘fclose’ was not declared in this scope
seperate.cpp:138:25: error: ‘fopen’ was not declared in this scope
seperate.cpp:141:11: error: ‘stderr’ was not declared in this scope
seperate.cpp:141:54: error: ‘fprintf’ was not declared in this scope
seperate.cpp:142:9: error: ‘exit’ was not declared in this scope
seperate.cpp:153:36: error: ‘fwrite’ was not declared in this scope
seperate.cpp:162:11: error: ‘stderr’ was not declared in this scope
seperate.cpp:162:54: error: ‘fprintf’ was not declared in this scope
seperate.cpp:163:9: error: ‘exit’ was not declared in this scope
seperate.cpp:174:36: error: ‘fwrite’ was not declared in this scope
seperate.cpp:183:11: error: ‘stderr’ was not declared in this scope
seperate.cpp:183:54: error: ‘fprintf’ was not declared in this scope
seperate.cpp:184:9: error: ‘exit’ was not declared in this scope
seperate.cpp:195:36: error: ‘fwrite’ was not declared in this scope
dfo#ubuntu:~/Desktop/abc-master$ g++ -v
You need to include stdio.h for fwrite and FILE.
#include <stdio.h>
The standard allows headers to include other headers, but you cannot rely on these indirect includes. You need to explicitly include every header you intend to use.
Related
I've been trying to compile a Hello World OpenGL application on OSX Lion. I have tried compilling the following file with g++ main.cpp -o test -lglut
#include <GL/glut.h>
void displayMe(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.5, 0.0, 0.0);
glVertex3f(0.5, 0.5, 0.0);
glVertex3f(0.0, 0.5, 0.0);
glEnd();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(300, 300);
glutInitWindowPosition(100, 100);
glutCreateWindow("Hello world :D");
glutDisplayFunc(displayMe);
glutMainLoop();
return 0;
}
But I get the following errors:
In file included from /usr/local/include/GL/glut.h:17,
from main.cpp:1:
/usr/local/include/GL/freeglut_std.h:122:19: error: GL/gl.h: No such file or directory
/usr/local/include/GL/freeglut_std.h:123:20: error: GL/glu.h: No such file or directory
In file included from /usr/local/include/GL/glut.h:17,
from main.cpp:1:
/usr/local/include/GL/freeglut_std.h:439: error: variable or field ‘glutUseLayer’ declared void
/usr/local/include/GL/freeglut_std.h:439: error: ‘GLenum’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:498: error: ‘GLenum’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:499: error: ‘GLenum’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:501: error: ‘GLenum’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:516: error: variable or field ‘glutWireCube’ declared void
/usr/local/include/GL/freeglut_std.h:516: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:517: error: variable or field ‘glutSolidCube’ declared void
/usr/local/include/GL/freeglut_std.h:517: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:518: error: variable or field ‘glutWireSphere’ declared void
/usr/local/include/GL/freeglut_std.h:518: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:518: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:518: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:519: error: variable or field ‘glutSolidSphere’ declared void
/usr/local/include/GL/freeglut_std.h:519: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:519: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:519: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:520: error: variable or field ‘glutWireCone’ declared void
/usr/local/include/GL/freeglut_std.h:520: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:520: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:520: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:520: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:521: error: variable or field ‘glutSolidCone’ declared void
/usr/local/include/GL/freeglut_std.h:521: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:521: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:521: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:521: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:523: error: variable or field ‘glutWireTorus’ declared void
/usr/local/include/GL/freeglut_std.h:523: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:523: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:523: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:523: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:524: error: variable or field ‘glutSolidTorus’ declared void
/usr/local/include/GL/freeglut_std.h:524: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:524: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:524: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:524: error: ‘GLint’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:537: error: variable or field ‘glutWireTeapot’ declared void
/usr/local/include/GL/freeglut_std.h:537: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:538: error: variable or field ‘glutSolidTeapot’ declared void
/usr/local/include/GL/freeglut_std.h:538: error: ‘GLdouble’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:546: error: ‘GLenum’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:551: error: ‘GLenum’ was not declared in this scope
/usr/local/include/GL/freeglut_std.h:560: error: ‘GLfloat’ has not been declared
/usr/local/include/GL/freeglut_std.h:560: error: ‘GLfloat’ has not been declared
/usr/local/include/GL/freeglut_std.h:560: error: ‘GLfloat’ has not been declared
/usr/local/include/GL/freeglut_std.h:561: error: ‘GLfloat’ does not name a type
main.cpp: In function ‘void displayMe()’:
main.cpp:5: error: ‘GL_COLOR_BUFFER_BIT’ was not declared in this scope
main.cpp:5: error: ‘glClear’ was not declared in this scope
main.cpp:6: error: ‘GL_POLYGON’ was not declared in this scope
main.cpp:6: error: ‘glBegin’ was not declared in this scope
main.cpp:7: error: ‘glVertex3f’ was not declared in this scope
main.cpp:11: error: ‘glEnd’ was not declared in this scope
main.cpp:12: error: ‘glFlush’ was not declared in this scope
Mac OS X is a very non-standard platform. You have encountered one of those situations. In particular, instead of linking against the GL and GLUT libraries on OS X, you use the appropriate framework: -framework OpenGL and -framework GLUT instead of -lGL and -lglut
In your code, you should have something like this:
#ifdef __APPLE__
# include <OpenGL/gl.h>
# include <OpenGL/glu.h>
# include <GLUT/glut.h>
#else
# include <GL/gl.h>
# include <GL/glu.h>
# include <GL/glut.h>
#endif
Generally speaking you'll need a lot more #ifdef __APPLE__ hacks to write code that works on OS X and other more standard platforms. But this should cover most of the bases for OS X. Also note that anything that uses glew or libraries like it should be completely pre-processed out on OS X; you (generally) don't load extensions at run-time on OS X.
I am getting these errors when I am compiling my code. I have all the headers under user/include
g++ -Ip_appmanager/inc -Icore/inc p_appmanager/src/appmanager_process.cpp -o p_appmanager/obj/appmanager -lpthread -lparser
p_appmanager/src/appmanager_process.cpp: In function ‘int main(int, char**)’:
p_appmanager/src/appmanager_process.cpp:33:21: error: ‘getpid’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:101:19: error: ‘fork’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:105:70: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:109:19: error: ‘getppid’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:124:19: error: ‘fork’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:128:61: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:132:19: error: ‘getppid’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:147:19: error: ‘fork’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:151:73: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:155:19: error: ‘getppid’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:170:19: error: ‘fork’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:175:70: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:179:19: error: ‘getppid’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp: In function ‘void* pingThread(void*)’:
p_appmanager/src/appmanager_process.cpp:302:11: error: ‘sleep’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp: In function ‘void* fifoThread(void*)’:
p_appmanager/src/appmanager_process.cpp:815:22: error: ‘fork’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:818:72: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:842:64: error: ‘execl’ was not declared in this scope
p_appmanager/src/appmanager_process.cpp:865:72: error: ‘execl’ was not declared in this scope
make: *** [all] Error 1
my kernel version is "Linux amit-bhaira 3.8.0-26-generic #38-Ubuntu SMP Mon Jun 17 21:46:08 UTC 2013 i686 i686 i686 GNU/Linux" . Same code is running on another linux machine.
please help me to fix this problem.
Thanks.
Add #include <unistd.h>
It works on other platforms because they are compiling with an old version of gcc (<4.7) which accidentally included unistd.h in some system headers.
From the fork(2) man page:
SYNOPSIS
#include <unistd.h>
From the exec(3) man page:
SYNOPSIS
#include <unistd.h>
From the getpid(2) man page:
SYNOPSIS
#include <sys/types.h>
#include <unistd.h>
From the sleep(3) man page:
SYNOPSIS
#include <unistd.h>
You have forgotten #include <unistd.h> in your program.
I have one .h which has the class in it and two .cpp, One being the main and the other holding the functions.
My complier is giving me theses errors
Functions.cpp: In member function âvoid Flandre::add()â:
Functions.cpp:10:3: error: âcinâ was not declared in this scope
Functions.cpp:12:33: error: âstrlenâ was not declared in this scope
Functions.cpp:16:6: error: âcoutâ was not declared in this scope
Functions.cpp:16:57: error: âendlâ was not declared in this scope
Functions.cpp:21:7: error: âcoutâ was not declared in this scope
Functions.cpp:21:53: error: âendlâ was not declared in this scope
Functions.cpp:27:9: error: name lookup of âiâ changed for ISO âforâ scoping [-f
Functions.cpp:27:9: note: (if you use â-fpermissiveâ G++ will accept your code)
Functions.cpp:27:16: error: âKYUUâ was not declared in this scope
Functions.cpp:32:6: error: âcoutâ was not declared in this scope
Functions.cpp:32:57: error: âendlâ was not declared in this scope
Functions.cpp:35:17: error: expected primary-expression before â[â token
Functions.cpp:37:14: error: expected unqualified-id before â[â token
Functions.cpp:38:14: error: expected unqualified-id before â[â token
Functions.cpp:39:14: error: expected unqualified-id before â[â token
I think it has something to do with the #include header in Functions
Newprogram2.cpp
>#include <iostream>
#include <string>
#include "newprogram2.h"
Functions.cpp
Some parts are missing but I just want it to complied so I can get add() to work first.
#include "newprogram2.h"
newprogram2.h
#ifndef NEWPROGRAM2_H
#define NEWPROGRAM2_H
#include<string>
using namespace std;
#endif
You have to include the proper headers for the functions you want to use.
For cin, cout and endl you need to #include <iostream>, you forgot to do that in your 2nd .cpp file
The compiler doesn't recognize strlen as a function because it is not in <string> (see http://www.cplusplus.com/reference/string/) but in <string.h> (see http://www.cplusplus.com/reference/cstring/strlen/).
I suggest you use either size() or length(), these are in <string>, both of these can be called on std::string objects.
Functions.cpp:27:16: error: âKYUUâ was not declared in this scope
This error shows because you try to access a variable you declared in another .cpp file. The .cpp file you are trying to access it in doesn't know this variable. You can fix that by moving the variable into the header file.
Functions.cpp:27:9: error: name lookup of âiâ changed for ISO âforâ scoping
This can be fixed by changing this
for(i=0;i<=KYUU;i++)
to this
for(int i=0;i<=KYUU;i++)
Functions.cpp:35:17: error: expected primary-expression before â[â token
Functions.cpp:37:14: error: expected unqualified-id before â[â token
Functions.cpp:38:14: error: expected unqualified-id before â[â token
Functions.cpp:39:14: error: expected unqualified-id before â[â token
These errors show because you try to call functions directly on a class instead of an object instantiated from that class, like this Flandre[i].getid(). You cannot do that, make an object instead and call the functions on the object.
I have successfully generated the .py and .cpp files needed using:
swig -c++ -python sf_c_api.i
but now I'm trying to make the shared object (.so) and I'm getting swamped with errors.
g++ -Wall -g -fPIC -I/usr/include/python2.6 -c atob.c fish.c maby_swap.c pwd_file.c pwd.c setup_fish.c shs.c sf_c_api.cpp sha1.cpp sf_c_api_wrap.cpp
Can anyone make heads or tails of this g++ output?
In file included from /usr/include/python2.6/Python.h:8,
from sf_c_api_wrap.cpp:149:
/usr/include/python2.6/pyconfig.h:1038:1: warning: "_XOPEN_SOURCE" redefined
<built-in>: warning: this is the location of the previous definition
In file included from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/postypes.h:42,
from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:42,
from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/string:42,
from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/stdexcept:39,
from sf_c_api_wrap.cpp:3024:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:143: error: ‘::btowc’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:148: error: ‘::fwide’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:149: error: ‘::fwprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:150: error: ‘::fwscanf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:153: error: ‘::mbrlen’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:154: error: ‘::mbrtowc’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:155: error: ‘::mbsinit’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:156: error: ‘::mbsrtowcs’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:159: error: ‘::swprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:160: error: ‘::swscanf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:162: error: ‘::vfwprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:166: error: ‘::vswprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:170: error: ‘::vwprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:174: error: ‘::wcrtomb’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:185: error: ‘::wcsrtombs’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:195: error: ‘::wctob’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:196: error: ‘::wmemcmp’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:197: error: ‘::wmemcpy’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:198: error: ‘::wmemmove’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:199: error: ‘::wmemset’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:200: error: ‘::wprintf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:201: error: ‘::wscanf’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:205: error: ‘::wcsstr’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:206: error: ‘::wmemchr’ has not been declared
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar: In function ‘wchar_t* std::wcsstr(wchar_t*, const wchar_t*)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:223: error: invalid conversion from ‘const wchar_t*’ to ‘wchar_t*’
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:223: error: initializing argument 1 of ‘wchar_t* std::wcsstr(wchar_t*, const wchar_t*)’
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar: In function ‘wchar_t* std::wmemchr(wchar_t*, wchar_t, size_t)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:227: error: invalid conversion from ‘const wchar_t*’ to ‘wchar_t*’
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/cwchar:227: error: initializing argument 1 of ‘wchar_t* std::wmemchr(wchar_t*, wchar_t, size_t)’
In file included from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/string:42,
from /usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/stdexcept:39,
from sf_c_api_wrap.cpp:3024:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h: In static member function ‘static int std::char_traits<wchar_t>::compare(const wchar_t*, const wchar_t*, size_t)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:330: error: ‘wmemcmp’ was not declared in this scope/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h: In static member function ‘static const wchar_t* std::char_traits<wchar_t>::find(const wchar_t*, size_t, const wchar_t&)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:338: error: initializing argument 1 of ‘wchar_t* std::wmemchr(wchar_t*, wchar_t, size_t)’
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h: In static member function ‘static wchar_t* std::char_traits<wchar_t>::move(wchar_t*, const wchar_t*, size_t)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:342: error: ‘wmemmove’ was not declared in this scope
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h: In static member function ‘static wchar_t* std::char_traits<wchar_t>::copy(wchar_t*, const wchar_t*, size_t)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:346: error: ‘wmemcpy’ was not declared in this scope
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h: In static member function ‘static wchar_t* std::char_traits<wchar_t>::assign(wchar_t*, size_t, wchar_t)’:
/usr/gcc/4.4/lib/gcc/i386-pc-solaris2.11/4.4.4/../../../../include/c++/4.4.4/bits/char_traits.h:350: error: ‘wmemset’ was not declared in this scope
/../include/c++/4.4.4/bits/char_traits.h:338: error: invalid conversion from ‘const wchar_t*’ to ‘wchar_t*’
I found a solution.
The problem is that under solaris:
If -D_XOPEN_SOURCE_EXTENDED=1, g++ cannot compile even an empty body
that #includes <iostream>. If it's undefined, then gcc cannot compile
C code.
[source]
and from /usr/include/python2.6/pyconfig.h:
/* Define to activate Unix95-and-earlier features */
#define _XOPEN_SOURCE_EXTENDED 1
Removing the XOPEN definitions fixed my problem.
I am getting the following error for STL files on GCC 4.1.2. And the same code works properly without any compilation errors on GCC 3.4.6.
I am including some built-in headers in my code that in turn include these STL files. Hence, I cannot modify the header files.
I compile it using the following:
gcc -I/grid/0/gs/java/jdk64/current/include -I/grid/0/gs/java/jdk64/current/include/linux -I/grid/0/tmp/direct/include/ydmg/ ydmg.cpp -I/grid/0/tmp/direct/include/ -o libydmg.so
Do I need to include some other parameter while compiling?
Could the compiler version be the cause of this problem?
The error is as follows:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:157: error: expected type-specifier
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:157: error: expected `>'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:157: error: expected unqualified-id before â>â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:932: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:932: error: âbool ytl::std::operator==(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:932: error: âbool ytl::std::operator==(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator==(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:933: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:933: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:934: error: âequalâ is not a member of âytl::stdâ
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:949: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:949: error: âbool ytl::std::operator<(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:949: error: âbool ytl::std::operator<(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator<(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:950: error: âlexicographical_compareâ is not a member of âytl::stdâ
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:950: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:951: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:956: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:956: error: âbool ytl::std::operator!=(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:956: error: âbool ytl::std::operator!=(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator!=(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:957: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:957: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:962: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:962: error: âbool ytl::std::operator>(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:962: error: âbool ytl::std::operator>(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator>(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:963: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:963: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:968: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:968: error: âbool ytl::std::operator<=(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:968: error: âbool ytl::std::operator<=(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator<=(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:969: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:969: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:974: error: expected â,â or â...â before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:974: error: âbool ytl::std::operator>=(int)â must have an argument of class or enumerated type
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:974: error: âbool ytl::std::operator>=(int)â must take exactly two arguments
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: In function âbool ytl::std::operator>=(int)â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:975: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:975: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h: At global scope:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: variable or field âswapâ declared void
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: âytl::std::swapâ declared as an âinlineâ variable
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: template declaration of âint ytl::std::swapâ
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: âvectorâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: expected primary-expression before â,â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: expected primary-expression before â>â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: â__xâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: âvectorâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: expected primary-expression before â,â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: expected primary-expression before â>â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:980: error: â__yâ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:110: error: expected template-name before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:110: error: expected `{' before â<â token
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_bvector.h:110: error: expected unqualified-id before â<â token
Any help would be appreciated.
Here is the C++ code.
I am calling the methods from ydmg and yut libraries using JNI.
This code is working perfectly fine on gcc 3.4.6. Its gives errors on gcc 4.1.2.
#include <stdio.h>
#include "ydmg/bd.h"
#include <jni.h>
#include "yut/string.h"
extern "C" int getAge();
JNIEXPORT jint JNICALL Java_ydmgBd_getAge(JNIEnv *, jobject)
{
ydmgBd bdObject;
yutString s = bdObject.getKeys();
printf("\ngetKeys() returns the key as : %s",s.c_str());
yutHash user;
yutString value = "abc";
yutString key ="login";
user.set(key,value);
ydmgBd bd1(user);
bool val = bd1.save(user);
if(val){
printf("\ntrue");
}else {
printf("\nfalse");
}
int age = bd1.getAge();
printf("\nAge : %d ",age);
printf("\nhi");
return 1;
}
int main(){
return 0;
}
If you compile cpp code with gcc and not with g++, you must link with -lstdc++, so that option is definitely missing.
However, the problem already occurs at the parsing step, so my suggestion is to check the namespaces... e.g. have a look at the error output:
...
ytl::std::operator!=
...
std should not be in your personal ytl namespace. You are doing something wrong with your includes.
One of your header files is almost certainly including:
#include <vector>
Before that line, add:
#undef max
And I believe your compiles will start working. This is happening b/c you are also using the C std library, which for some functions uses macros, and in this case, causes the preprocessor to freak out. I've seen this same error on Linux, and undefining that symbol was all i needed to get things compiling again.