2

I want to run a C project on Compiler Explorer (godbolt.org) which includes some external header files. What is the procedure to include these third-party header files on there?

Screenshot of the project

Suppose I want to run this code which includes snipmath.h file. Also, snipmath.h header includes other lib files. How can I include all of them in godbolt? like we usually do in a offline compiler.

Maruf Monem
  • 21
  • 1
  • 3
  • As an `#include` directive just does dumb insertion of the file content, you might just copy the content into your own file manually. But as Lundin already mentioned, most headers are useless without the corresponding impementation which comes in an additioal C file or library. And including a header is not sufficient for using a library. – Gerhardh Sep 02 '21 at 11:30
  • 2
    That is not what Compiler Explorer is for. It is for exploring compiling behavior with small samples of code, not compiling complicated things with extra header files. If you cannot easily embed the necessary code from the headers in the code you paste into Compiler Explorer, you should be compiling on your own system. With GCC and Clang, you can use the `-S` option to ask them to generate assembly code for you to examine. – Eric Postpischil Sep 02 '21 at 11:41
  • I have edited the description and included a screenshot. Please check. – Maruf Monem Sep 02 '21 at 16:36

2 Answers2

5

Remarkably, only 1 week before you posted the question this feature was added to compiler explorer. As of Nov 2021 it is reported to still have some rough edges, and not every combination of controls work - but starting from the simple template Matt delivered and following his instructions work for me:

  • go to compiler explorer

  • click "Add..." at the very top left and choose "Tree (IDE mode)".

  • Move the files you have open into "Included files" with the plus (you will have to give them names)

  • (For C++) tick "CMake" and then create a CMakeLists.txt with appropriate info it in

  • Ensure it says -DCMAKE_BUILD_TYPE=Debug in the box under

  • In the box under that choose the name of your target, e.g. "test"

  • You can then "Add new..." and make a compiler that will run CMake

Note this does not include uploading the headers, but rather pasting them in new CE editors. Also, judging by your screenshot - when you write 'other lib files' I assume you mean other headers. Lib files aren't supported.

If your project was a CMake one, you might have been able to upload it directly (someone did).

Ofek Shilon
  • 14,734
  • 5
  • 67
  • 101
0

You can use Compiler Explorer with Cmake and have multiple header and source files. You could even have some other files to read from (like *.ini). Try it here reading *.ini in Compiler Explorer

Note: the examples are with C++, but it must be straightforward to do it with C.

stoycho
  • 223
  • 3
  • 17