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*
744 Discussions

Is it possible to write a cmake file to use g++ as the host compiler?

dongbai
Beginner
2,346 Views

Hello!

my scenario: I want to add some sycl files to an existing c++ project that uses g++ as the compiler. In order to reduce the cost of replacing compiler, I want to use dpc++ only as the sycl device compiler. 

 

https://www.intel.com/content/www/us/en/docs/dpcpp-cpp-compiler/developer-guide-reference/2023-2/use-third-party-compiler-as-host-compiler-dpc-code.html

This link provides a way to use g++ as host compiler, but only for a simple demo. 

Is there a cmake file example that can achieve mixed compilation (g++ and dpc++)?

Looking forward to your reply!

0 Kudos
1 Solution
NoorjahanSk_Intel
Moderator
1,899 Views

Hi,


>>One thing I want to make sure is that the host compilation option `-fPIC` in makfile is required ?


Thank you for your patience.


-fPIC option is required if the object files are eventually linked to output a shared library. It is not necessary to use -fPIC option while doing host-side compilation using a third party compiler.


Please refer to below link for more details:

https://www.intel.com/content/www/us/en/docs/dpcpp-cpp-compiler/developer-guide-reference/2023-2/fpic.html


Hope we answered all your queries, Could you please confirm whether we can close this thread from our end?


Thanks & Regards,

Noorjahan.


View solution in original post

0 Kudos
7 Replies
NoorjahanSk_Intel
Moderator
2,263 Views

Hi,


Thanks for posting in Intel Communities.


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


Thanks & Regards,

Noorjahan.


0 Kudos
NoorjahanSk_Intel
Moderator
2,202 Views

Hi,

 

CMake only keeps one set of compiler properties which is shared by all targets in a CMakeLists.txt file. If you want to use two compilers, you need to run CMake twice

 

I have tried with Makefile using some sample programs with oneAPI compiler 2023.2 and g++ 11.4 on Ubuntu 20.04

Please find the attached zip file for the Makefile and code samples.

Please try building the Makefile using the following commands:

1. make

2 ./my_program

 

If this does not match your use-case, Could you please share a sample reproducer and CMake file if you have tried any at your end?

 

Thanks & Regards,

Noorjahan.

 

0 Kudos
dongbai
Beginner
2,033 Views

Thank you for your excellent work, this solved my problem very well !

One thing I want to make sure is that the host compilation option `-fPIC` in makfile is required ?

0 Kudos
NoorjahanSk_Intel
Moderator
2,058 Views

Hi,


We haven't heard back from you. Could you please provide an update on your issue?


Thanks & Regards,

Noorjahan.


0 Kudos
NoorjahanSk_Intel
Moderator
1,946 Views

Hi,


>>this solved my problem very well 

Thank you for trying our solution.


>>One thing I want to make sure is that the host compilation option `-fPIC` in makfile is required ?

We are working on it and we will get back to you soon.


Thanks & Regards,

Noorjahan.



0 Kudos
NoorjahanSk_Intel
Moderator
1,900 Views

Hi,


>>One thing I want to make sure is that the host compilation option `-fPIC` in makfile is required ?


Thank you for your patience.


-fPIC option is required if the object files are eventually linked to output a shared library. It is not necessary to use -fPIC option while doing host-side compilation using a third party compiler.


Please refer to below link for more details:

https://www.intel.com/content/www/us/en/docs/dpcpp-cpp-compiler/developer-guide-reference/2023-2/fpic.html


Hope we answered all your queries, Could you please confirm whether we can close this thread from our end?


Thanks & Regards,

Noorjahan.


0 Kudos
NoorjahanSk_Intel
Moderator
1,890 Views

Hi,


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


Thanks & Regards,

Noorjahan.


0 Kudos
Reply