0

I downloaded homebrew, gcc14 and pasted the path on compiler.

Then it worked when I pasted the flags:

 -DCMAKE_C_FLAGS="-Wall -Werror -pedantic-errors -lm -g"

But it didn’t build and showed:

FAILED: CMakeFiles/HW0.dir/main.c.o
/usr/bin/gcc   -Wall -Werror -lm -pedantic-errors -g -g -std=gnu99 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk -fcolor-diagnostics -MD -MT CMakeFiles/HW0.dir/main.c.o -MF CMakeFiles/HW0.dir/main.c.o.d -o CMakeFiles/HW0.dir/main.c.o -c /Users/noharbatit/CLionProjects/HW0/main.c
clang: error: -lm: 'linker' input unused \[-Werror,-Wunused-command-line-argument\]
ninja: build stopped: subcommand failed.

I have MacBook intel chip with macOS 15 sequoia help please

I tried to redownload clion homebrew reinstall Xcode paste path directly.

but it seems nothing is working

5
  • 1
    You mix a linker option with the compiler options. The linker option -l (lower-case L) is for linking a library. The compiler creating an object file have no need for it. Commented Nov 12, 2024 at 13:26
  • And don't set flags and options through variables like CMAKE_C_FLAGS. Use the suitable CMake commands instead: target_compile_options for compilation of source to object files; And target_link_libraries to link with libraries. Commented Nov 12, 2024 at 13:29
  • @Someprogrammerdude I pasted the exact flags the course gave me. it’s the demand of the course, I can’t do something else so it will pass tests Commented Nov 12, 2024 at 16:14
  • The problem might be that the tutor or teacher expects you to do it all manually on the command line, compiling and linking as a single step. If you use a tool like CMake (which CLion uses for its projects) then it will build as two different steps: Source to object file, and object file to executable program. You can still use the same flags the tutor/teacher told you to use, but you need to separate them them, so the compile-to-object file options are used only for that, and the link-to-executable flags are used only for that. Commented Nov 12, 2024 at 16:20
  • The changes you need to make in your CMakeLists.txt file is basically adding these two lines: target_compile_options(your_target PUBLIC -Wall -Werror -pedantic-errors -g) and target_link_options(your_target PUBLIC m). All the options provided by your tutor/teacher are there, but placed in their correct places. The your_target symbol is the name in the add_executable command. Commented Nov 12, 2024 at 16:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.