sockets.h problem with cygwin and eclipse - c

I keep getting this error:
c:\cygwin\usr\include/cygwin/socket.h:55:3: error: expected specifier-qualifier-list before '__uid32_t'
My code is mininmal and still can't compile:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
int main(void) {
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
return EXIT_SUCCESS;
}
I have include C:\cygwin\usr\include to compiler path and linker to C:\cygwin\usr\lib
please advise

Headers under C:\cygwin\usr\include, and libraries under C:\cygwin\usr\lib, are for use in the Cygwin environment -- which means they should be referred to via their Cygwin paths, /usr/include and /usr/lib.
I haven't used mingw, but I don't think it's part of Cygwin, and I wouldn't expect it to be able to use Cygwin's headers and libraries.
If you're going to use mingw, you should use the headers and libraries that are installed with it. Don't specify any Cygwin-related directories.
Or you can use Cygwin's gcc (which is optional; you'll have to install it with setup.exe). In that case, you can run gcc or make from the command line. I'm not sure whether Cygwin and Eclipse play nicely together.

I know this question is old, and I'm using a newer version, but I had a similar issue and it was resolved by moving #include <sys/socket.h> one line above #include <sys/types.h>.
Something in types.h appears to be blocking socket.h (not sure how). Wish I had more details on the cause, but hope the solution helps some.

Related

How to use asprintf in a flex rule, when _GNU_SOURCE not set?

In order to ensure that the asprintf function is visible in the header file <stdio.h>, I have followed the advice of the man page and put:
#define _GNU_SOURCE
#include <stdio.h>
// ... uses of asprintf();
This works in normal C programs, although presumably only on GNU/Linux and not on the BSDs.
I would like to be able to use the same trick in a flex lexer, e.g.:
%{
#define _GNU_SOURCE
#include <stdio.h>
%}
%%
\"[^\"].+\" {
asprintf(&(yylval.string), "%s", yytext);
return STRING;
}
%%
// ...
but I get a compile warning (implicit-function-declaration) for asprintf.
Upon further investigation, this is because in the C file that flex generates it includes <stdio.h> before my preamble code, without defining _GNU_SOURCE first.
How can I write code which uses this function which
compiles correctly inside flex rules, and
(optionally) also works in non-GNU environments?
Having re-checked the book that got me into the habit of using asprintf, I have discovered that it is indeed a GNU extension.
It is available in a GCC library called libiberty, which you can use in place of the _GNU_SOURCE macro.
I was able to install this on Ubuntu 15.10 and Debian 8.2 using:
sudo apt-get install libiberty-dev
I then modified the preamble to include:
%{
#include <libiberty/libiberty.h>
%}
and everything worked without any warnings.
Assuming that a libiberty package is available for non-Linux distributions (and given that it is part of GCC I would assume this would be the case) this solution should work cross platform (on POSIX-ish OS's.)

cmake not finding gl.h on OS X

I am on OS X 10.10 and trying to build a C 'project' with GLUT and OpenGL.
I reduced it to a minimal example showcasing my problem. I have the following CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
FIND_PACKAGE(OpenGL REQUIRED)
FIND_PACKAGE(GLUT REQUIRED)
if(OpenGL_FOUND) # never true, but printed as true
link_directories(${OpenGL_LIBRARY_DIRS})
include_directories(${OpenGL_INCLUDE_DIR})
endif(OpenGL_FOUND)
if(GLUT_FOUND)
link_directories(${GLUT_LIBRARY_DIR})
include_directories(${GLUT_INCLUDE_DIR})
endif(GLUT_FOUND)
# print all vars because wtf
get_cmake_property(_v VARIABLES)
foreach(_v ${_v})
message(STATUS "${_v}=${${_v}}")
endforeach()
add_executable(main main.c)
target_link_libraries(main ${GLUT_LIBRARY} ${OPENGL_LIBRARY})
The main.c is just a dummy including two headers:
#include <gl.h>
#include <glut.h>
int main()
{
return 0;
}
Now, cmake . runs fine and for debugging purposes prints all variables. I took the code from somewhere, I do not know enough about cmake to know whether it's doing what I think it is. Anyway, running make returns
main.c:1:10: fatal error: 'gl.h' file not found
#include <gl.h>
^
1 error generated.
The header gl.h is actually present in /System/Library/Frameworks/OpenGL.framework/Headers and as such should be found by cmake, especially since glut.h is in the same structure (simply replace OpenGL with GLUT) and is found just fine. Also, what is confusing to me is that the block in if(GLUT_FOUND)... is never executed (try to put a message statement into it), but among the printed variables it says OPENGL_FOUND=TRUE. But removing the if-condition does not change anything.
The actual question: What the hell is going on? Why does a) cmake not find the header unless specifically included, b) the if-block not execute although OPENGL_FOUND prints as TRUE, c) no such problems occur with glut.h? Spent hours on this and can't fathom why.
It's common to do
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif
You can see this being done in one form or another in glfw, glew, sfml and others
I'm surprised that you found OpenGL headers in /System/Library/Frameworks in OS X 10.10. I don't think they have been installed there in quite a few Xcode releases. The most recent header files with Xcode 6.1 on 10.10 should be in:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/OpenGL.framework/Headers
You don't really need to know this path, unless you want to go look at the headers. I believe the compiler automatically uses the SDK that matches the OS you're compiling on. If for some reason you wanted to build for a different platform, you can override that logic with the -isysroot compiler option.
With header files that come from a framework, the naming you use in your #include statement is:
#include <FrameworkName/HeaderFileName.h>
The compiler will resolve this to the actual pathname of the header within the framework.
Therefore, if you want to use the current OpenGL header, which is gl3.h, from the OpenGL framework, the correct include statement is:
#include <OpenGL/gl3.h>
This will give you access to the Core Profile of the highest supported OpenGL version (which is 3.x or 4.x if you have a reasonably new Mac). Or if you want to use OpenGL 2.1 with legacy features:
#include <OpenGL/gl.h>
As pointed out bei pmr, CMake variables are case-sensitive, so the variable OPENGL_FOUND must be queried.
Also, as PeterT wrote, the header is included as #include <OpenGL/gl.h> on OS X.
I ended up coming to this question after updating qt installed from homebrew and had the same error messages. Going off of Reto's comment, I updated CMAKE_OSX_SYSROOT to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk and everything went back to working as expected.

Eclipse project cannot include tchar.h

I am trying to build an lzmat_lib compression library using Eclipse with Cygwin gcc. I downloaded the library from the link http://www.matcode.com/lzmat_lib.zip. The file has the following include files:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <tchar.h>
#include "lzmat.h"
It cannot find the tchar.h header file. I do not understand how to add this header file. Please suggest a solution.
Your options are to install a Windows development environment, like Visual Studio or mingw along with the Windows SDK, or to port the code to your cygwin (posix) environment.
To port the code, you'd just do this:
Remove #include <tchar.h>.
Search and replace _TCHAR to char.
Search the file for all strings beginning with _t and remove that prefix. E.g., _tfopen becomes just fopen. _tprintf becomes printf.
Search for the text _T and remove it. You could also remove the extra parentheses that will then surround your string.
Deal with any other issues as they come up by removing the dependency on tchar.h and using a standard function instead.

how can I invoke setjmp on ubuntu 11.10?

I'm reading expert c, and got through setjump and longjump section, so want make the code running on my ubuntu 11.10, but when I include setjump.h, the gcc compiler complain that it can't find the header file, I find there is not a setjump.h in the /user/include/ directory.
So what should I do? Can you give me some suggestions?
From the setjmp(3) man page:
SYNOPSIS
#include <setjmp.h>

Libraries not found in Cygwin

When trying to compile this program:
#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
printf("Hey there\n");
return 0;
}
i get compiler-error:
test.c:1:24: netinet/in.h: No such file or directory
test.c:2:24: sys/socket.h: No such file or directory
test.c:3:19: netdb.h: No such file or directory
I use Cygwin (in Windows). Seems the compiler doesnt find any of the libraries exept a few core ones (stdio, string..., stdlib also works...). Is this a linking issue or does it have something to do with my installation of Cygwin? Do i have to specify that i want these libraries included when installing Cygwin? Please help, i'm dying here...
You'll need to run cygwin's setup.exe again, and find the packages that contain the headers you need. Maybe there's a unix net package somewhere.
You might want to try MingW (http://www.mingw.org).

Resources