Intel® oneAPI DPC++/C++ Compiler
Talk to fellow users of Intel® oneAPI DPC++/C++ Compiler and companion tools like Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and Intel® Distribution for GDB*

How to call C program form dpcpp program?

Ikei
Beginner
1,623 Views

I have a cpp program which calls some c routines. I am trying to port the cpp program to DPC++. However when I compile the program by changing the compiler from "Intel C++ Compiler 2022" to "Intel(r) OneAPI DPC++ Compiler 2022", it fails to link.  I made a test case as below:

------ main.cpp -------

extern "C" {
void f(int);
};
void code(int i)
{
f(i);
}

int main(void)
{
code(10);
}

---------- func.c ------

/* C code: */
#include <stdio.h>
void f(int i)
{
printf("f() is called!");
}

------------

 

--------------- output of Microsoft Visual Studio Community 2019 Version 16.11.16

1>------ ビルド開始: プロジェクト: dpcpp_call_c, 構成: Debug x64 ------
1>main-7ce443.obj : : error LNK2019: 未解決の外部シンボル f が関数 "void __cdecl code(int)" (?code@@YAXH@Z) で参照されました
1> 定義済みの一致する可能性があるシンボルに関するヒント:
1> "void __cdecl f(int)" (?f@@YAXH@Z)
1>C:\\Users\\mikei\\source\\repos\\dpcpp_call_c\\x64\\Debug\\dpcpp_call_c.exe : : error LNK1120: 1 件の未解決の外部参照
1>dpcpp: : error : linker command failed with exit code 1120 (use -v to see invocation)
1>プロジェクト "dpcpp_call_c.vcxproj" のビルドが終了しました -- 失敗。
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ 

 

I think I am doing something stupid. Would you please teach me how to fix it?

Thanks.

 

-Mitsuru

 

0 Kudos
7 Replies
VarshaS_Intel
Moderator
1,592 Views

Hi,

 

Thanks for the posting in Intel Communities.

 

Please find the below-attached codes where we are able to run successfully using the DPCPP compiler. Please find the below screenshot for more details:

linking.png

Also, we have observed that you are using Microsoft Visual Studio(16.11.16) which is not supported by Intel oneAPI as of now. We recommend you to use the supported Microsoft Visual Studio versions with Intel oneAPI.

 

For the Microsoft Visual Studio Compatibility with Intel oneAPI, please find the below link :

https://www.intel.com/content/www/us/en/developer/articles/reference-implementation/intel-compilers-compatibility-with-microsoft-visual-studio-and-xcode.html

 

Please let us know if you are still facing any issues.

 

Thanks & Regards,

Varsha

 

 

0 Kudos
Ikei
Beginner
1,581 Views

Hi,

 

Thank you for your quick response.  I have confirmed it works. So do I need to put "

extern "C" {}" in all of my xxx.c programs? Wouldn't dpcpp asume "xxx.c" as c program? 

-Mitsuru

 

0 Kudos
VarshaS_Intel
Moderator
1,535 Views

Hi,


We are working on your issue. We will get back to you soon.


Thanks & Regards,

Varsha


0 Kudos
VarshaS_Intel
Moderator
1,506 Views

Hi,


>>Wouldn't dpcpp asume "xxx.c" as c program? 

Sorry for the inconvenience caused to you. DPCPP compiler won't assume as C code. Since the paths to the c and cpp compilers will differ, we need to use the extern C() explicitly to run the code successfully.


Thanks & Regards,

Varsha


0 Kudos
VarshaS_Intel
Moderator
1,466 Views

Hi,


We have not heard back from you. Could you please provide an update on your issue?


Thanks & Regards,

Varsha


0 Kudos
Ikei
Beginner
1,460 Views

Varsha,

 

Thank you for your quick response and support mails after. I found a temporal resolution for this. I change the compiler for all C programs to MS one by Visual Studio. And I am now struggling for other issues concerning how to rewrite kernel part for DPC++. So I will leave this issue for a while until I can run the kernel on Intel GPU.

 

Please close this issue.

 

Thank you again.

 -Ikei

0 Kudos
VarshaS_Intel
Moderator
1,435 Views

Hi,


>>Please close this issue.

Thanks for the confirmation. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Thanks & Regards,

Varsha




0 Kudos
Reply