C compiler errors on TUN/TAP - c++

I like to create a TUN/TAP interface out of a C++ program. I found a straight foward tutorial on the net at
http://backreference.org/2010/03/26/tuntap-interface-tutorial/.
The problem is, that I seem to have linking problems with with if.h and if_tun.h.
When I strip the tutorial to the minimal example below, only to open a slot, I get a number of errors.
Example:
#include <linux/if.h>
#include <linux/if_tun.h>
int main(void){
char *clonedev = "/dev/net/tun";
open(clonedev,O_RDWR);
return 0;
}
If think this should compile, yet I get the following errors:
/usr/include/linux/if.h:184:19: error: field 'ifru_addr' has incomplete type
/usr/include/linux/if.h:185:19: error: field 'ifru_dstaddr' has incomplete type
/usr/include/linux/if.h:186:19: error: field 'ifru_broadaddr' has incomplete type
/usr/include/linux/if.h:187:19: error: field 'ifru_netmask' has incomplete type
/usr/include/linux/if.h:188:20: error: field 'ifru_hwaddr' has incomplete type
tuntap.cpp: In function 'int main()':
tuntap.cpp:6:18: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
tuntap.cpp:7:15: error: 'O_RDWR' was not declared in this scope
tuntap.cpp:7:21: error: 'open' was not declared in this scope
I'm using GCC 4.7.2 (in this case, from the command line without any switches) on Fedora 18 with Linux 3.11.4.
What's wrong with my libraries?

Try a different include. Use ...
#include <net/if.h>
... instead of ...
#include <linux/if.h>
In addition, include another file.
#include <fcntl.h>

Related

How to resolve - error: there are no arguments to 'exit' that depend on a template parameter

As the question makes clear, I am working with templates, a template class to be precise. The code in question is found within a public member function of the template class and is a simple exit(1); command. The error message produced is error: there are no arguments to ‘exit’ that depend on a template parameter, so a declaration of ‘exit’ must be available [-fpermissive]. I am only getting this error after compiling using g++ 4.8.1, 4.2.1 did not produce this error.
You need to include <stdlib.h> or <cstdlib> (and use std::exit). It worked previously because the previous compiler probably had that header included implicitly by a different header.

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

gl3w error from c++ file

I have a project where I first build gl3w.c with gcc and then my own OGLGraphics.cpp file with g++. Gcc successfully compiles gl3w.c but when g++ attempts to compile the file that includes gl3w.h I get these errors:
In file included from /mnt/hgfs/grace/src/grace-output/graphics/OGLGraphics.cpp:22:0:
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:69:8: error: ‘PFNGLDRAWARRAYSPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:70:8: error: ‘PFNGLDRAWELEMENTSPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:71:8: error: ‘PFNGLGETPOINTERVPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:72:8: error: ‘PFNGLPOLYGONOFFSETPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:73:8: error: ‘PFNGLCOPYTEXIMAGE1DPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:74:8: error: ‘PFNGLCOPYTEXIMAGE2DPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:75:8: error: ‘PFNGLCOPYTEXSUBIMAGE1DPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:76:8: error: ‘PFNGLCOPYTEXSUBIMAGE2DPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:77:8: error: ‘PFNGLTEXSUBIMAGE1DPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:78:8: error: ‘PFNGLTEXSUBIMAGE2DPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:79:8: error: ‘PFNGLBINDTEXTUREPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:80:8: error: ‘PFNGLDELETETEXTURESPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:81:8: error: ‘PFNGLGENTEXTURESPROC’ does not name a type
/mnt/hgfs/grace/src/grace-output/include/GL3/gl3w.h:82:8: error: ‘PFNGLISTEXTUREPROC’ does not name a type
I don't know why it works with a C file but not from C++?
Did you follow the procedure as outlined in GL3W's readme file? Specifically, the part about including gl3w.h first, before any OpenGL files.
Oh, and before window.h, which can include gl.h.
extern PFNGLDRAWARRAYSPROC gl3wDrawArrays; <—— unknown type name PFNGLDRAWARRAYSPROC
This error is caused by the inclusion of #include <OpenGL/gl.h> in your code such as GLTriangleBatch.h. If you substitute #include "GL/gl3w.h” instead, which is OpenGL 3/4 calls, then this will remove the error. I think that there is a conflict between different versions of OpenGL calls and this results in the unknown type error. I ran into this same problem myself when I was trying to port SuperBible 5 code into SB6.

basic_string expected initializer compile error

When i try to compile the following code:
#include <string.h>
using namespace std;
typedef std::basic_string<char> foostring;
foostring foo = "foo";
I get the following error:
stringtest.cpp:5: error: expected initializer before ‘<’ token
stringtest.cpp:6: error: ‘foostring’ does not name a type
My compiler is: g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1
What am i doing wrong? i intend to use this with windows TCHAR for unicode support once i figure out how to use it.
The header is <string>, not <string.h>.
None of the standard library headers end with an extension. (You're including the C header string.h, which should be included in C++ via <cstring>, had that been what you actually wanted.)