0

I'm developing a program for raspberry pi pico with HAT from Ubuntu. I'm using arm-none-eabi-gcc with cmake. I want to include sys/socket.h for tcp/ip socket programming

From the command: $ echo | arm-none-eabi-gcc -v -x c -E -, I get this

/usr/lib/gcc/arm-none-eabi/6.3.1/include

/usr/lib/gcc/arm-none-eabi/6.3.1/include-fixed

/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/include

Thus getting no such file or directory when I try to compile .c file with #include <sys/socket.h>

I want to include /usr/include and its subdirectories where socket.h file is included.

How can I add /usr/include when compiling. Also should I instead use newlib for the pico machine?

simony1124
  • 1
  • 1
  • 1
  • gcc ... -I -L – long.kl Mar 03 '22 at 09:42
  • I don't understand... are you doing bare metal development or Linux development? I thought the Pico thing was a microcontroller? – Lundin Mar 03 '22 at 10:42
  • Im developing on a linux machine first and compile .c file. The current toolchain compiles .c to .uf2 file. Then I will drag and drop .uf2 file onto the pico which is microcontroller as you said. @Lundin – simony1124 Mar 03 '22 at 10:53
  • @simony1124 But how exactly do you get the TCP/IP stack and Linux sockets into the microcontroller? – Lundin Mar 03 '22 at 11:02
  • @Lundin First I want to preface with that it is my first time doing embedded programming, and I've done only android/server programming (Yeah Im a noob and dont want to confuse you lol). There is this ethernet HAT module developed by Wiznet co.(https://maker.wiznet.io/) that adds TCP/IP ability to the MCU. – simony1124 Mar 03 '22 at 11:19
  • @simony1124 Ok so you should use whatever API that library provides then. If it isn't the same one as Linux sockets use, then you have to drop the idea of compiling/testing this in Linux and develop on the target system instead. Which is always a good idea anyway. – Lundin Mar 03 '22 at 11:25
  • I have set up my aws server and want the MCU to make a http request. So I've setup vscode in linux for rp2040 blindly following the youtube tutorials, but basically I'm stuck after trying to include socket header. – simony1124 Mar 03 '22 at 11:27
  • @Lundin Pico is OS free, does it mean including socket.h won't do anything? And that is why you suggested me to use their library? – simony1124 Mar 03 '22 at 11:33
  • 1
    You need to use whatever socket lib that is present on your target, simple as that. There's no reason why sys/socket would be available unless someone decided to implement that one as a HAL on top of some TCP/IP stack for the target. – Lundin Mar 03 '22 at 11:41

2 Answers2

0

You cannot use the gcc-arm-none-eabi toolchain if you want to use operating system features like sockets. That toolchain can only be used for embedded code, that runs without operating system support and therefore operating system headers are not provided. I would recommend you to compile your code with the regular gcc installed directly on the raspberry pi and not try to cross compile. A correct cross compiling toolchain is an advanced subject and it is difficult to setup.

Edit
If you really want or need to use a cross compiler (compile on the Ubuntu machine rather than directly on the pi) you maybe find this question and its answers helpful.

Jakob Stark
  • 3,346
  • 6
  • 22
0
  1. the version of arm-none-eabi-gcc is old;
  2. it cloud be using default path, trying to modify the path in the 'makefile':e.g.:a) <sys/socket.h> b)<linux/socket.h>
  3. the libs cloud be lost, trying to use 'sudo apt install' to slove.
gogogo
  • 1
  • 2
  • a) the OP is not using a 'makefile', b) `` should not be used directly as it is not part of the official C api (see for example [here](https://stackoverflow.com/questions/10278433/why-does-linux-socket-h-file-not-define-socket-types)) and c) `sudo apt install` will -- just as you asked it to do -- install nothing. – Jakob Stark Mar 03 '22 at 10:28
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 03 '22 at 12:59