Errors in ./your_program.sh when running first task in Build your own HTTP

Hi,
I started the “Build your own HTTP” project in C and I am getting the following error when trying to run my HTTP server locally:

-- Running vcpkg install
All requested packages are currently installed.
Total install time: 49.9 us
-- Running vcpkg install - done
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (1.0s)
-- Generating done (0.0s)
-- Build files have been written to: /home/sarthak/Documents/self-learn/codecrafters/codecrafters-http-server-c/build
[ 33%] Building C object CMakeFiles/http-server.dir/src/CMakeFiles/3.16.3/CompilerIdC/CMakeCCompilerId.c.o
[ 66%] Building C object CMakeFiles/http-server.dir/src/main.c.o
[100%] Linking C executable http-server
/usr/bin/ld: CMakeFiles/http-server.dir/src/main.c.o: in function `main':
main.c:(.text+0x0): multiple definition of `main'; CMakeFiles/http-server.dir/src/CMakeFiles/3.16.3/CompilerIdC/CMakeCCompilerId.c.o:CMakeCCompilerId.c:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/http-server.dir/build.make:116: http-server] Error 1
make[1]: *** [CMakeFiles/Makefile2:87: CMakeFiles/http-server.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

I have installed cmake version 4.0. Pls help me debug this linker error saying that I have 2 instances of the function main.
I have not currently made any changes to my repository, I have only uncommented the code as the first task “Bind to a port” and I wanted to run it locally.

Hey @sarthaktanwani, could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

Hey @andy1li thanks for the response
It is working for me now. I had an earlier version of cmake (v3.18) running on my Zorin (Ubuntu based) system. Unfortunately, cmake is not updated in Ubuntu apt repositories.

I had to update the repository, reinstall cmake (v4.0).
Ref: software installation - How do I install the latest version of cmake from the command line? - Ask Ubuntu

I was getting the error because some of the build files were generated using an earlier version of cmake so I had to remove the entire codecrafters repo, clone it again and then run the example.

Hope this helps someone in the future!

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.