Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference

ID 767253
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Modify Your makefile

If you use makefiles to build your GCC* application, you need to change the value for the GCC compiler variable to use the Intel® oneAPI DPC++/C++ Compiler. You may also want to review the options specified by CFLAGS. For example, a sample GCC makefile:

# Use gcc compiler 
  CC = gcc 

# Compile-time flags 
  CFLAGS = -O2 -std=c99 
all: area_app 

area_app: area_main.o area_functions.o
    $(CC) area_main.o area_functions.o -o area 

area_main.o: area_main.c
    $(CC) -c $(CFLAGS) area_main.c 

area_functions.o: area_functions.c
    $(CC) -c -fno-asm $(CFLAGS) area_functions.c 

clean: rm -rf *o area

Modified makefile for the Intel® oneAPI DPC++/C++ Compiler

In this example, the name of the compiler is changed to use icpx

# Use Intel DPC++/C++ Compiler
  CC = icpx

# Compile-time flags 
  CFLAGS = -std=c99 
all: area_app 

area_app: area_main.o area_functions.o
    $(CC) area_main.o area_functions.o -o area 

area_main.o: area_main.c
    $(CC) -c $(CFLAGS) area_main.c 

area_functions.o: area_functions.c
    $(CC) -c -fno-asm $(CFLAGS) area_functions.c 

clean: rm -rf *o area

If your GCC code includes features that are not supported with the Intel® oneAPI DPC++/C++ Compiler (compiler options, language extensions, macros, pragmas, and so on), you can compile those sources separately with GCC if necessary.

In the above makefile, area_functions.c is an example of a source file that includes features unique to GCC. Because the Intel® oneAPI DPC++/C++ Compiler uses the O2 option by default and GCC uses option O0 as the default, we instruct GCC to compile at option O2. We also include the -fno-asm switch from the original makefile because this switch is not supported with the Intel® oneAPI DPC++/C++ Compiler. The following sample makefile is modified for using the Intel® oneAPI DPC++/C++ Compiler and GCC together:

# Use Intel DPC++/C++ Compiler
  CC = icpx
# Use gcc for files that cannot be compiled by icpx
  GCC = gcc
# Compile-time flags 
  CFLAGS = -std=c99 
all: area_app 

area_app: area_main.o area_functions.o
    $(CC) area_main.o area_functions.o -o area 

area_main.o: area_main.c
    $(CC) -c $(CFLAGS) area_main.c 

area_functions.o: area_functions.c
    $(GCC) -c -O2 -fno-asm $(CFLAGS) area_functions.c 

clean: rm -rf *o area

Output of make using a modified makefile:


icpx -c -std=c99 area_main.c
gcc -c -O2 -fno-asm -std=c99 area_functions.c
icpx area_main.o area_functions.o -o area

Use IPO in Makefiles

By default, IPO generates "dummy" object files containing Interprocedural information used by the compiler. To link or create static libraries with these object files requires special LLVM-provided tools. To use them in your makefile, simply replace references to "ld" with "lld-link" and references to "ar" with "llvm-ar", or use the Intel® oneAPI DPC++/C++ Compiler to link as shown in the example:

# Use Intel DPC++/C++ Compiler 
  CC =icpx
# Compile-time flags 
  CFLAGS = -std=c99 -ipo
all: area_app 

area_app: area_main.o area_functions.o
    $(CC) area_main.o area_functions.o -o area 

area_main.o: area_main.c
    $(CC) -c $(CFLAGS) area_main.c 

area_functions.o: area_functions.c
    $(CC) -c $(CFLAGS) area_functions.c 

clean: rm -rf *o area