0

My code:

#include <fcgi_stdio.h>

int main() {
    int count = 0;
    while(FCGI_Accept() >= 0) {
        printf("Content-type: text/html\r\n");
        printf("\r\n");
        printf("Hello world!<br>\r\n");
        printf("Request number %d.", count++);
    }
}

In a fresh instance of multipass, I installed gcc, g++ and libfcfgi-dev as

sudo apt-get install gcc
sudo apt-get install g++
sudo apt-get install libfgci-dev

But attempting to compile the code using g++ -std=c++17 -lfgci++ -lfcgi main.cpp -o main gives the error

in function main: undefined reference to `FCGX_Init` ...

But this doesn't happen when I try to compile in gcc:latest docker container. The dockerfile is

FROM gcc:latest
RUN apt-get update -yqq;
    apt-get install -yqq libfcgi-dev
COPY ./main.cpp /home/main.cpp
CMD g++ -std=c++17 /home/main.cpp -lfcgi++ -lfcgi -o /home/main

What am i missing in the multipass instance?

Lisarra D
  • 1
  • 1
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – 273K Dec 15 '20 at 03:21
  • @S.M. not really as it is linking in the docker container successfully, not in multipass only – Lisarra D Dec 15 '20 at 03:23
  • The order matters: libraries follow input files. – 273K Dec 15 '20 at 03:24
  • @S.M. I will try it out but any idea why would it matter in once case but not in the other? – Lisarra D Dec 15 '20 at 03:26
  • Look carefully at the command you are using in the docker. – 273K Dec 15 '20 at 03:29
  • @S.M.Ah i see, that was the case. I really feel silly now looking at that. Thank for pointing it out. You were really helfpul – Lisarra D Dec 15 '20 at 03:33

1 Answers1

0

The order matters: libraries follow input files

Like it was mentioned in the comments, it was indeed the case. I didn't know that and I totally missed that it was in the right order in the dockerfile. It was a really simple thing indeed but thanks to S.M for his quick response in pointing out the silly mistake. Hope this also helps out some other fellow newbie stumbling upon this issue in the future.

Lisarra D
  • 1
  • 1