C Include files not found when compiling C program.

Sorry for the newbie question. I am just starting to learn C programming.
I am running pfSense, a modified (smaller) FreeBSD 10.3 version to implement a router/firewall. I would like to compile some simple C programs, like the classical:

Code:
#include<stdio.h>

int main()
{
printf("\nHello World,\nWelcome to my first C program in Linux\n");

return(0);
}

But I get:

Code:
$ gcc --version
gcc (FreeBSD Ports Collection) 4.9.4
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc helloworld.c
In file included from helloworld.c:1:0:
/usr/local/lib/gcc49/gcc/x86_64-portbld-freebsd10.3/4.9.4/include-fixed/stdio.h:53:23: fatal error: sys/cdefs.h: No such file or directory
 #include <sys/cdefs.h>
                       ^
compilation terminated.
$ clang35 helloworld.c
helloworld.c:1:9: fatal error: 'stdio.h' file not found
#include<stdio.h>
        ^
1 error generated.

Same results if I change stdio.h to stdlib.h.

Could someone please tell me what is wrong here? Maybe I need to download such ".h" files?

Even when my FreeBSD version is a restricted one, I usually success in downloading and installing packages from here:
http://pkg.freebsd.org/freebsd:10:x86:64/latest/All/

But, in this case, I don't know what package should I install.
 
Your program is perfectly valid. I stored it in foo.c:
Code:
# gcc -Wall foo.c -o foo.exe
# ./foo.exe

Hello World,
Welcome to my first C program in Linux
#
and compiled it on FreeBSD (recent version, 11.3). And then I repeated the same thing with clang, and I repeated it again on Linux with gcc.

This means that your compiler installation is broken. I have no idea about pfSense, but FreeBSD 10.3 is ancient, and has long been unsupported. However, it worked fine in its time, and had a functioning compiler. So something is broken in the way your include files and libraries are installed. I have no idea whether using pkg with FreeBSD packages on pfSense is supposed to work.

(Style remark: Please put a space between "#include" and "<stdio.h>. Looks better, and matches common coding style.)
 
The wrong thing is pfsense. As you see, it compiles well in a standard FreeBSD install.

First of all, there is no support for BSD derivative here, see: https://forums.freebsd.org/threads/pc-bsd-freenas-xigmanas-and-all-other-freebsd-derivatives.7290/

Nevertheless, I advise you to think twice before customizing psfense. The system settings are very peculiar. Most of the configuration files do nothing if you change them (including rc.conf).

Don't add package except if you know exactly what you are doing because the FreeBSD standard packages use these well-known configuration files. I think it's not so difficult to broke pfsense in this way.

If you want to play with C, use a standard FreeBSD installation (or linux or Windows or whatever) but not pfsense.
 
The wrong thing is pfsense. As you see, it compiles well in a standard FreeBSD install.

If you want to play with C, use a standard FreeBSD installation (or linux or Windows or whatever) but not pfsense.
Since I am just trying to run a C program on pfSense, I am researching right now in order to find the way to develop it from some IDE running on Linux or Windows (like NetBeans, Code::Blocks or Eclipse), but compiling it to FreeBSD binary.

I think it must be possible.

Wish me good luck, and thanks you again.
 
Hi Fanta,
you have misunderstood user Emrion - to create a "HelloWorld" C-binary for FreeBSD you need neither luck, nor Windows, nor Linux, nor an IDE. The only thing you need is FreeBSD (and an editor / compiler of course). Cross-compiling is different, so you can work on it later in your career. You make absolutely no mistake using Netbeans and Eclipse on FreeBSD, but for your purpose the same editor you've already used is enough. And then you can finally write:
printf ("\ nHello World, \ nWelcome to my firstC program in FreeBSD \ n"); :)
 
Thanks you, ucomp, but my problem is that I need to run some simple (mostly CSV files management matters) C programs on a pfSense version, that is not fully (not a complete one) FreeBSD. So I assumed that compiling a simple "Hello World" C program to FreeBSD binary would be a first step.

Sadly I can not install a full FreeBSD operating system, I must go on with pfSense, so I have no GUI nor even (as seen on this thread) a complete compiler installation.
That is why I am trying to cross-compile.
 
That is why I am trying to cross-compile.
please try to cross-compile openjdk11 for us ... just kidding :) ...
Sadly I can not install a full FreeBSD operating system
that's really sad, but why not?
you can install it in vmware/virtualbox ... on an old computer ... nearly everywhere except on your iPhone ;-)
it's a very quick installation - progress and you don't need xorg to compile your app. And the best for you: Millions of FreeBSD-forum-users will help you to get the best possible results , assumed you have installed FreeBSD ;-)
 
I use to install pfSense on old computers to my clients to make them work as a router and firewall. It is incredibly stable and includes some useful out-of-the-box features like balance loading.

The FreeBSD core makes it very efficient, and, as long as I can add Bash, and some other GNU tools to the operating system, I use to script on Bash for this computer some small programs that measure and collect bandwith usage, WiFi repeaters clients, ping status of the computers in the network and so on. A log creation's program, we could say.

Installing a full FreeBSD operating system would require for me to implement the complete router, firewall, balance load, traffic filtering... etc.

Everything is OK with the pfSense solution, until now, that my Bash scripts are starting to need to deal with bigger log files. So I am going to attempt the C/C++ solution for efficiency matters.
 
Back
Top