Position of compiler flag -l

后端 未结 2 929
孤城傲影
孤城傲影 2021-01-06 13:04

I\'m currently learning OpenCL. Now, when I want to compile my program, I get an error with this command:

g++ -Wall -l OpenCL main.cpp -o main
2条回答
  •  失恋的感觉
    2021-01-06 13:55

    Order of [most] arguments to g++ is very important.

    Libraries should go last (at least after source and object files). You can't really change that.

    The -l should preferably be glued to the library name:

     g++ -Wall main.cpp -o main -lOpenCL
     #                          ^^^ glue the -l to the library name
    

    You probably want to also pass -g (in addition of -Wall) to the compiler to get a debuggable binary. Use the gdb debugger.

    As James Kanze commented, you might want to replace -g with -ggdb if using specifically gdb.

提交回复
热议问题