我目前正在学习 OpenCL.现在,当我想编译我的程序时,我收到以下命令的错误:
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
所以我的问题是,我该怎么做才能在命令前面使用 -l 标志?(背景是:我想使用 Netbeans 编译我的程序,当我在 -> 属性 -> 构建 -> C++ 编译器 -> 附加选项下添加标志时,它将放入位置,显示在第一个命令中)
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)
预先感谢您的帮助
错误代码如下:
/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
g++
[大多数] 参数的顺序非常重要.
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.
-l
最好粘合到库名:
g++ -Wall main.cpp -o main -lOpenCL
# ^^^ glue the -l to the library name
您可能还想将 -g
(除了 -Wall
)传递给编译器以获得可调试的二进制文件.使用 gdb
调试器.
You probably want to also pass -g
(in addition of -Wall
) to the compiler to get a debuggable binary. Use the gdb
debugger.
正如 James Kanze 评论的那样,您可能想要替换 -g
使用 -ggdb
如果专门使用 gdb
.
As James Kanze commented, you might want to replace -g
with -ggdb
if using specifically gdb
.
这篇关于编译器标志的位置 -l的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!