Libraries not found in Cygwin - c

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).

Related

My C Code exe only runs on my PC. How do I Include VCRuntime140.dll in my C code exe

I have recently been getting in C code.
I would like to create a stand alone .exe that can run on a windows PC.
The exe runs on my pc, of course because of the installation. However, on another PC I get an error
> code execution cannot proceed because vcruntime140d.dll was not found
How do I include this dll so that it will run on any PC
Any assistance will be fantastic.
Its a very simple code, see below
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
int main(int argc, char* argv[])
{
printf("\n\nHi there.\n\nThis is a .exe test.\n\n If you are seeing this, it is successful.\n\n");
system("pause");
}
I have googled this for a couple of days now, there has not been a real answer to my question.
EDIT after last comment
Here are the settings I have adjusted
I did select x64

Include ext4.h in C program

I'm trying to create a little program that can read the ext4 filesystem, and for that i need to use all the structures that are defined in the ext4.h file.
Problem is, that this file includes a set of kernel headers such as
#include <linux/blkdev.h>
#include <linux/magic.h>
#include <linux/jbd2.h>
#include <linux/quota.h>
#include <linux/rwsem.h>
#include <linux/rbtree.h>
#include <linux/seqlock.h>
#include <linux/mutex.h>
#include <linux/timer.h>
#include <linux/version.h>
... and more
I've installed the kernel headers using:
$ apt search linux-headers-$(uname -r)
So now i have them in /usr/src/linux-headers-5.4.../include and i try to compile my program with -I /path/to/kernel-headers but now it seems that there're headers included in those headers that it can't find such as asm/current.h which in my filesystem is asm-generic/current.h
Do someone that ever did something like this can help me?
I suggest you take a look at e2fsprogs. This is the user-space toolset for manipulating ext2/3/4 filesystems, and it contains a userspace implementation of the filesystem you can adapt.

Why no <string.h> in getopt library?

I have been using Ludvig Jerabek's port of the GNU getopt on Windows and getting errors on lines like:
if (d->optind != argc && !_tcscmp(argv[d->optind], _T("--")))
_tcscmp is a macro that resolves to strcmp on my system and then it reports strcmp not found. If we examine the headers in getopt.cpp:
/* Getopt for Microsoft C
....
Date: 02/03/2011 - Ludvik Jerabek - Initial Release
....
Revisions:
....
08/09/2011
....
#include <stdlib.h>
#include <stdio.h>
#include "getopt.h"
We see the problem: <string.h> is not included. I guess in Visual Studio <string.h> is included automatically maybe? I know I have successfully built getopt.cpp in Visual Studio, but using a manual environment with gcc on MinGW it is complaining about all the string compare functions being missing. What is the explanation for this?
The real tchar.h causes either #include <string.h> or #include <mbstring.h> depending on the character-set macros.
You have a broken version of tchar.h that does not correctly emulate these Microsoft-specific "Generic-Text Routine Mappings".

Compile C program with visual studio

I am required to explain what the program located in the following links does:
main.c
csapp.c
csapp.h
I compile the following code in linux as:
............................................................
(note all three files have to be in the same working directory for compilation to work. )
that command is: gcc main.c csapp.c
when I execute that command I get the executable: a.out and I get no compilation errors!
That executable file can be downloaded from here (I don't think you need that file plus I will not execute that file if I where you).
Anyways I think that if I could debug the program I will be able to understand better what is going on. As a result I have created a C++ console empty console project in visual studio. I will like to include the same files in there and be able to compile it. I have never used c++ before and I don't really understand where to place header files. This is what I have done hoping to be able to compile the program:
The program will not compile if I place the files like that.
I have also tried placing all the files in the same directory just like on the linux virtual machine:
that does not compile either.
How will I be able to compile that program with visual studio?
If you look at csapp.h you'll notice it tries to include these headers:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <setjmp.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <math.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
Some of these are std C headers, but others are specific to POSIX/Linux/UNIX style operating systems (pthread.h for example). You won't be able to use these libraries on Windows or in Visual Studio unless you're doing something unusual like compiling against Cygwin libraries.
If you want to get an understanding of what the program is doing, there's a number of things you could do. First off, just read through the code and look up the functions it calls in the man pages which document those functions (If you have gcc, I guess you also have man?) second, yes you could print to console to figure stuff out. You could also use a debugger like gdb to step through the program, it's not as intuitive as VS debugger but it works...

sockets.h problem with cygwin and eclipse

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.

Resources