[英]Position of compiler flag -l
我正在學習OpenCL。 現在,當我想編譯我的程序時,我得到一個錯誤:
g++ -Wall -l OpenCL main.cpp -o main
錯誤大多是未定義的引用,因為我沒有鏈接庫(不過我會在最后發布錯誤代碼)。
但是使用這個命令一切正常:
g++ -Wall main.cpp -o main -l OpenCL
所以我的問題是,我需要做什么,在命令前使用-l Flag? (背景是:我想使用Netbeans編譯我的程序,當我在 - >屬性 - >構建 - > C ++編譯器 - >附加選項下添加標志時,它將放入位置,如第一個命令所示)
在此先感謝您的幫助
這是錯誤代碼:
/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++
的[大多數]參數的順序非常重要。
庫應該是最后的(至少在源文件和目標文件之后)。 你不能真正改變它。
最好將-l
粘貼到庫名:
g++ -Wall main.cpp -o main -lOpenCL
# ^^^ glue the -l to the library name
您可能還希望將-g
(除了-Wall
)傳遞給編譯器以獲取可調試的二進制文件。 使用gdb
調試器。
正如James Kanze評論的那樣,如果使用專門的gdb
,你可能想用-ggdb
替換-g
。
使用g ++(通常在Unix下),- -l
指定輸入源( .a
或.so
),並按順序處理輸入。 當輸入是靜態庫( .a
文件)時,將掃描解析未定義引用的對象; 如果它是.so
,則其中沒有任何目標文件,但如果它解析了一些未定義的符號,它仍然只會被考慮在內。
在任何目標文件之前放置-l
,還沒有未定義的符號,因此程序中不會包含任何內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.