Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting error syntax error: unexpected "("When building a C program in Docker

I am trying to build a C program inside a Docker container, I just would like to create a binary file and execute it in the container. I receive no error during compilation but
when running within my container the binary file created on Linux Alpine I get this error message:

/usr/jjj-app/bin # ./jjj-linux.out 
./jjj-linux.out: line 1: syntax error: unexpected "("
/usr/jjj-app/bin # 

Notes: I am running make build-linux from the host, in my case macOS.

Any ideas how to build this simple program in Linux environment using Docker? I can use Alpine or another.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

main.c

#include <stdio.h>

int main() {
   printf("Hello, World!");
   return 0;
}

Makefile

build-linux:
    docker build -t jjj-app .
    docker run --publish 8081:8080 jjj-app

Dockerfile

FROM alpine
RUN apk update
RUN apk add build-base
COPY . /usr/jjj-app
WORKDIR /usr/jjj-app
RUN gcc /usr/jjj-app/src/main.c -o /usr/jjj-app/bin/jjj-linux.out -r

>Solution :

The gcc -r flag is for partial linking. Presumably to do whole program optimization or other linker steps later on.

If you want a finished exectuable you need to finish linking it.

Either by running gcc again gcc /usr/jjj-app/bin/jjj-linux.out -o /usr/jjj-app/bin/jjj-linux.done.out

or just removing the -r

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading