Visual studio 14.0 LNK2001 (unresolved external sy

2019-06-09 17:25发布

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!!!

2条回答
虎瘦雄心在
2楼-- · 2019-06-09 17:51

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)

查看更多
太酷不给撩
3楼-- · 2019-06-09 18:06

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".

查看更多
登录 后发表回答