0

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

doqtor
  • 8,414
  • 2
  • 20
  • 36
Kaiyuan
  • 3
  • 1
  • 3
  • Please specify where did you add the paths of libs and header files? The compiler is complaining about CRT functions not OpenCL functions. – Hadi Brais Jul 06 '15 at 10:11
  • I added them in property page. Additional include directories and additional library directories. – Kaiyuan Jul 06 '15 at 10:18
  • That's not enough. You need to add the required library names to `Linker/Input/Additional Dependencies`. – Hadi Brais Jul 06 '15 at 10:34
  • OK, now all other errors disappeared, after I added the OpenCL.lib file to Additional Dependencies. But there is still one similar error. `LNK2001 unresolved external symbol __imp_sprintf hello_world C:\Users\S_KW\OpenCL\hello_world\OpenCL.lib(icd_windows.obj) 1` I think this error has something to do with OpenCL.lib, right? – Kaiyuan Jul 06 '15 at 10:55
  • Yes. It says that `OpenCL.lib` cannot find a definition of `sprintf`. – Hadi Brais Jul 06 '15 at 11:05
  • But, I think the definition of print function is bulit in C++ like stdio.h, right? Why it cannot be found? – Kaiyuan Jul 06 '15 at 11:12
  • Can specify all the linker errors you are seeing? – Hadi Brais Jul 06 '15 at 11:16
  • This is the only LNK error for now.`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` – Kaiyuan Jul 06 '15 at 11:19

2 Answers2

2

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)

Community
  • 1
  • 1
liuyz
  • 106
  • 8
  • The problem is still unsolved. Now I only use VS to write the host code. For the kernel code, I use CL Editor to edit and the rest job uses Altera SDK. – Kaiyuan Jul 27 '15 at 12:11
  • @liuyz you may want to see my answer for VS2015 fix. – doqtor Oct 06 '15 at 21:05
  • @doqtor thanks for let us know, 1st, is the ICD to fix __imp__iob_func unresolved issue? 2nd, in the step 1, a makefile needs to be modified, is this one of the makefile in the lib folder? or a makefile for the MS project? i'm not aware of any makefile in my project folder. 3rd, in step 2, it requires to add key for each lib returns from aocl ldlibs command in a right order, which order are you using? thanks. – liuyz Oct 08 '15 at 03:14
  • @liuyz Re 1. fix for unresolved issue is to link with additional libraries as per my answer, Re 2. this is VS project without any makefiles, you need to modify project settings as per my answer, Re 3. I converted example VS2010 project into VS2015 and all AOCL tasks added in *.vcxproj stay there so no need to worry about the order of libraries generated by aocl compile and link config. See also my updated answer, I tried to make it clearer. – doqtor Oct 08 '15 at 08:42
  • @doqtor im starting with vector_add as you suggested, by adding the 2 additional libs, i have no problem to compile the host program, but the host cannot find the altera platform when running. Then I added the alteracl_icd.dll in Khronos key, it can pick up the Altera platform by clGetPlatformIDs, but fails at clGetDeviceIDs, no device is returned, and the status code is -1. Any ideas? thx – liuyz Oct 13 '15 at 00:19
  • @liuyz You also need to add Altera key with path to *mmd.dll. Also make sure `aocl diagnose` is successful, you have all necessary paths added to PATH without ALTERAOCLSDKROOT. – doqtor Oct 13 '15 at 10:31
  • @doqtor yep, the Altera Key and all system PATH are added, and the aocl diagnose are working as well. I have my environment working for VS2013, but not VS2015. After following the fix in your post below, my VS2013 environment is still working, but VS2015 can only compile host, but could not get DeviceID properly. Any suggestions? thx – liuyz Oct 13 '15 at 23:13
  • @liuyz try to run it under the debugger, maybe you will get an error which you don't normally get in release mode. Also on the same machine I have OpenCL SDK of another vendor installed, not sure if that can have any effect on this. – doqtor Oct 14 '15 at 18:55
  • @doqtor yes, the DeviceID not valid problem was captured in debug mode. before the device selection, after the platform query, 2 were found, Altera and NVidia. But the Altera one just could not being selected for next step. – liuyz Oct 15 '15 at 06:38
  • @doqtor thanks for the tips, I just managed give it a try today, and it works great. the host and kernel can run under VS2015 and Altera OpenCL SDK 15.1, thanks – liuyz Dec 03 '15 at 23:08
  • @doqtor I just found out today that if there are printf instructions in the kernel file, the kernel files will not compile as the aoc cannot find the definition of printf. do we need to include the legacy_stdio_definitions.lib during the kernel building stage? if so, how? thanks for help. – liuyz Jan 20 '16 at 01:18
  • @doqtor in addition to my previous question on including the legacy_stdio_definitions.lib, I have tried with -l and -L to provide the path information to aoc. but all failed, it seems -l only accept OpenCL related libs, hope this could be useful. – liuyz Jan 20 '16 at 05:15
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".

doqtor
  • 8,414
  • 2
  • 20
  • 36