Position of compiler flag -l

后端 未结 2 926
孤城傲影
孤城傲影 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:35

    With g++ (and generally under Unix), -l specifies a source of input (either a .a or a .so), and input is processed in order. When the input is a static library (a .a file), it will be scanned for objects which resolve undefined references; if it is a .so, there aren't any object files in it, but it will still only be taken into consideration if it resolves some undefined symbol.

    When you put the -l before any object files, there are no undefined symbols yet, so nothing will be incorporated into the program.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题