编译器标志位置-l [英] Position of compiler flag -l

查看:206
本文介绍了编译器标志位置-l的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习OpenCL。现在,当我想编译我的程序,我得到一个错误与此命令:

  g ++ -Wall -l OpenCL main。 CPP -o主要

的错误大多是未定义的引用,因为库不挂,我觉得(



但是使用这个命令一切正常:

  g ++ -Wall main.cpp -o main -l OpenCL 

所以我的问题是,我要做什么,在命令前使用-l标志?
(背景是:我想使用NetBeans编译我PROGRAMM,当我下添加的标志 - >属性 - >构建 - > C ++编译器 - >附加选项,就会把中的地位,在所示第一个命令)



先感谢您的帮助



这里是错误代码:

  /tmp/ccmKP4oI.o:在函数`cl :: detail :: ReferenceHandler< _cl_context *> :: release(_cl_context *)' 
的main.cpp :( text._ZN2cl6detail16ReferenceHandlerIP11_cl_contextE7releaseES3 _ [_ ZN2cl6detail16ReferenceHandlerIP11_cl_contextE7releaseES3 _] + 0×14):未定义的参考`clReleaseContext'
/tmp/ccmKP4oI.o:在功能`CL ::详细:: ReferenceHandler< _cl_command_queue * > ::发布(_cl_command_queue *)':
的main.cpp :( text._ZN2cl6detail16ReferenceHandlerIP17_cl_command_queueE7releaseES3 _ [_ ZN2cl6detail16ReferenceHandlerIP17_cl_command_queueE7releaseES3 _] + 0×14):未定义的参考`clReleaseCommandQueue'
/tmp/ccmKP4oI.o:在功能`CL ::平台::的getInfo(unsigned int类型,标准::字符串*)常量:
的main.cpp :( text._ZNK2cl8Platform7getInfoEjPSs [_ZNK2cl8Platform7getInfoEjPSs] + 0x22):未定义的参考`clGetPlatformInfo'
/tmp/ccmKP4oI.o:在函数`cl :: Platform :: get(std :: vector< cl :: Platform,std :: allocator< cl :: Platform> > *)':
的main.cpp :( text._ZN2cl8Platform3getEPSt6vectorIS0_SaIS0_EE [_ZN2cl8Platform3getEPSt6vectorIS0_SaIS0_EE] + 0×41):未定义的引用`clGetPlatformIDs'。
的main.cpp :( text._ZN2cl8Platform3getEPSt6vectorIS0_SaIS0_EE [_ZN2cl8Platform3getEPSt6vectorIS0_SaIS0_EE] + 0xb4。 ):未定义的引用`clGetPlatformIDs'
collect2:错误:LD返回1退出状态


解决方案

g ++ 的[most]参数顺序非常重要。



库应该最后(至少在源和目标文件之后)。



-l <​​/ code>最好是 到库名称:

  g ++ -Wall main.cpp -o main -lOpenCL 
#^^^ glue the -l到库名

您可能还想传递 -g (除了 -Wall ),以获得可调试的二进制。使用 gdb 调试程序。



As James Kanze 评论过,您可能想用 -ggdb -g $ c>如果特别使用 gdb


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

The errors are mostly undefined references, because the library is not linked, I think (nevertheless I will post the error code at the end).

But with this command everything works fine:

g++ -Wall main.cpp -o main -l OpenCL

So my question is, what do I have to do, to use the -l Flag in front of the command? (The Background is: I want to use Netbeans to compile my programm and when i add the flag under -> properties -> build -> C++ Compiler -> additional options, it will put in in the Position, shown in the first command)

Thanks in advance for your help

Here's the error code:

/tmp/ccmKP4oI.o: In function `cl::detail::ReferenceHandler<_cl_context*>::release(_cl_context*)':
main.cpp:(.text._ZN2cl6detail16ReferenceHandlerIP11_cl_contextE7releaseES3_[_ZN2cl6detail16ReferenceHandlerIP11_cl_contextE7releaseES3_]+0x14): undefined reference to `clReleaseContext'
/tmp/ccmKP4oI.o: In function `cl::detail::ReferenceHandler<_cl_command_queue*>::release(_cl_command_queue*)':
main.cpp:(.text._ZN2cl6detail16ReferenceHandlerIP17_cl_command_queueE7releaseES3_[_ZN2cl6detail16ReferenceHandlerIP17_cl_command_queueE7releaseES3_]+0x14): undefined reference to `clReleaseCommandQueue'
/tmp/ccmKP4oI.o: In function `cl::Platform::getInfo(unsigned int, std::string*) const':
main.cpp:(.text._ZNK2cl8Platform7getInfoEjPSs[_ZNK2cl8Platform7getInfoEjPSs]+0x22): undefined reference to `clGetPlatformInfo'
/tmp/ccmKP4oI.o: In function `cl::Platform::get(std::vector<cl::Platform, std::allocator<cl::Platform> >*)':
main.cpp:(.text._ZN2cl8Platform3getEPSt6vectorIS0_SaIS0_EE[_ZN2cl8Platform3getEPSt6vectorIS0_SaIS0_EE]+0x41): undefined reference to `clGetPlatformIDs'
main.cpp:(.text._ZN2cl8Platform3getEPSt6vectorIS0_SaIS0_EE[_ZN2cl8Platform3getEPSt6vectorIS0_SaIS0_EE]+0xb4): undefined reference to `clGetPlatformIDs'
collect2: error: ld returned 1 exit status

解决方案

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.

这篇关于编译器标志位置-l的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆