Visual studio 14.0 LNK2001 (unresolved external symbol ) with OpenCL

一笑奈何 提交于 2020-02-02 16:29:02

问题


I am new to OpenCL. When I tried the examples from the website of Altera, I got several LNK2001 errors as follows

Severity    Code    Description Project File    Line
Error   LNK2001 unresolved external symbol __imp_sprintf    hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_hal_mmd.obj)  1
Error   LNK2001 unresolved external symbol __imp___iob_func hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_hal_mmd.obj)  1
Error   LNK2001 unresolved external symbol __imp_fprintf    hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_hal_mmd.obj)  1
Error   LNK2001 unresolved external symbol __imp_sprintf    hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_mem.obj)  1
Error   LNK2001 unresolved external symbol __imp___iob_func hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_offline_hal.obj)  1
Error   LNK2001 unresolved external symbol __imp__set_output_format hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_printf.obj)   1
Error   LNK2001 unresolved external symbol __imp_fprintf    hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_profiler.obj) 1
Error   LNK2001 unresolved external symbol __imp_sprintf    hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_program.obj)  1
Error   LNK2001 unresolved external symbol __imp___iob_func hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_support.obj)  1
Error   LNK2001 unresolved external symbol __imp_vsprintf   hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_support.obj)  1
Error   LNK2001 unresolved external symbol __imp_vsnprintf  hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_support.obj)  1
Error   LNK2001 unresolved external symbol __imp_vfprintf   hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_support.obj)  1
Error   LNK2001 unresolved external symbol __imp___iob_func hello_world C:\Users\S_KW\OpenCL\hello_world\alteracl.lib(acl_threadsupport.obj)    1
Error   LNK1120 8 unresolved externals  hello_world C:\Users\S_KW\OpenCL\hello_world\bin\hello_world.exe    1
Error       IntelliSense: argument of type "void (*)(const char *errinfo, const void *, size_t, void *)" is incompatible with parameter of type "void (__stdcall *)(const char *, const void *, size_t, void *)"    hello_world c:\Users\S_KW\OpenCL\hello_world\host\src\main.cpp  145
Warning LNK4044 unrecognized option '/LC:\Users\S_KW\arrow_c5sockit_bsp\arm32\lib'; ignored hello_world C:\Users\S_KW\OpenCL\hello_world\LINK   1
Warning LNK4044 unrecognized option '/lalterahalmmd'; ignored   hello_world C:\Users\S_KW\OpenCL\hello_world\LINK   1
Warning LNK4044 unrecognized option '/lalterammdpcie'; ignored  hello_world C:\Users\S_KW\OpenCL\hello_world\LINK   1
Error   LNK2001 unresolved external symbol __imp_vsnprintf  hello_world C:\Users\S_KW\OpenCL\hello_world\MSVCRT.lib(vsnprintf.obj)  1
Error   LNK2001 unresolved external symbol __imp__vsnprintf hello_world C:\Users\S_KW\OpenCL\hello_world\MSVCRT.lib(vsnprintf.obj)  1
Error   LNK2001 unresolved external symbol __imp___iob_func hello_world C:\Users\S_KW\OpenCL\hello_world\pkg_editor.lib(pkg_editor.obj) 1
Error   LNK2001 unresolved external symbol __imp_fprintf    hello_world C:\Users\S_KW\OpenCL\hello_world\pkg_editor.lib(pkg_editor.obj) 1

I have already added path of the libs and head files. I am confused by those errors. What can I do to solve this?

----------------------------UPDATE------------------------------

OK, as Hadi Brais said, I added it to additional dependencies. And all of the old errors are gone. But there comes a new one.

Severity    Code    Description Project File    Line
Error   LNK1120 1 unresolved externals  hello_world C:\Users\S_KW\OpenCL\hello_world\bin\hello_world.exe    1
Error   LNK2001 unresolved external symbol __imp_sprintf    hello_world C:\Users\S_KW\OpenCL\hello_world\OpenCL.lib(icd_windows.obj)    1
Warning LNK4044 unrecognized option '/LC:\Users\S_KW\arrow_c5sockit_bsp\arm32\lib'; ignored hello_world C:\Users\S_KW\OpenCL\hello_world\LINK   1
Warning LNK4044 unrecognized option '/lalterahalmmd'; ignored   hello_world C:\Users\S_KW\OpenCL\hello_world\LINK   1
Warning LNK4044 unrecognized option '/lalterammdpcie'; ignored  hello_world C:\Users\S_KW\OpenCL\hello_world\LINK   1

This one has something to do with OpenCL.lib, I think. It seems that the lib cannot see the printf function. But I think the printf is built in C++. It is confusing. Someone know how to handle this? Thank you very much!!!


回答1:


Update: according to the discussion in this link, this issue is caused by the re-definition of the stdin/stdout/stderr in VS2015, and the Altera OpenCL libs were build with VS2010. The miss match of the function call makes it failed at linking stage.

The legacy_stdio_definitions.lib can be included to solve the __imp_vfprintf linking, but not __imp__iob_func.

According to one of the discussion with a MS engineer, there are two ways you can overcome this: 1. encapsulate the lib into a DLL that is linked with the same CRT that was used by Altera. 2. wait for newer release of the libs from Altera.

Hope this can help.


just would like to follow up your issue. Are you running Altera OpenCL designs with Visual Studio 2015? I get the same error as you mentioned. Have you got it fixed yet? Thx (ps: it seems the same design can run with VS2013 but failed on VS2015)




回答2:


There are 2 steps to make the project built under VS2015 work. I used VS2010 vector_add project converted into VS2015 and all AOCL tasks included in *.vcxproj generating compile and link config stays there.

1. Build host executable

In VS2015 add to Linker -> Input -> Additional Dependencies:

OpenCL.lib
legacy_stdio_definitions.lib

At this stage you should be able to run host executable but Altera platform will not be detected.

2. Add Altera OpenCL platform to Windows so that it can be queried by any OpenCL SDK

Follow "Linking to the ICD Loader Library on Windows" from "Altera SDK for OpenCL Programming Guide":

Specifically point 2b talking about adding values to the Windows registry:

[HKEY_LOCAL_MACHINE\SOFTWARE\Altera\OpenCL\Boards] 
"c:\\board_vendor a\\my_board_mmd.dll"=dword:00000000

and

[HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors]
"alteracl_icd.dll"=dword:00000000

If Altera OpenCL platform still can't be found then make sure below paths are in PATH (note: for some reason %ALTERAOCLSDKROOT% is not working for me so the paths are hard-coded): C:\altera\15.0\hld\bin;C:\altera\15.0\hld\host\windows64\bin.

I suggest first making it work with simple Altera example project i.e. "vector_add".



来源:https://stackoverflow.com/questions/31242820/visual-studio-14-0-lnk2001-unresolved-external-symbol-with-opencl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!