-fopenmp flag in compile and link

JuanPablo

I have this openmp code

#include <omp.h>
#include <stdio.h>

int main()
{
  #pragma omp parallel
  {
    fprintf(stderr, "thread %d\n", omp_get_thread_num());
  }

  return 0;
}

when I compile and link and use the -fopenmp

gcc-6 -std=c99 -Wall -Wextra -pedantic -fopenmp -Iinclude -c -o build/main.o src/main.c
gcc-6 -o bin/main  build/main.o  -fopenmp

the code work

$ ./bin/main 
thread 0
thread 1
thread 2
thread 3

but don't when I only put the flag in the link

gcc-6 -std=c99 -Wall -Wextra -pedantic -Iinclude -c -o build/main.o src/main.c
src/main.c: In function 'main':
src/main.c:6:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
   #pragma omp parallel
gcc-6 -o bin/main  build/main.o  -fopenmp

the code work but not in parallel

$ ./bin/main 
thread 0

why I need add -fopenmp in compile and link time?

Employed Russian

why I need add -fopenmp in compile and link time?

Because it is required both at compile time (to enable the #pragma omp handling) and at link time (to link required support libraries).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Link error during gcc compile with makefile

From Dev

Link and compile an assembly function

From Dev

Compile with standalone flag gives compilation errors in client code

From Dev

Angular JS Directive - Template, compile or link?

From Dev

how to override -DNDEBUG compile flag when building cython module

From Dev

Make: just link, skip compile

From Dev

How do I compile and link unit tests?

From Dev

How to compile and link against cddlib library?

From Dev

autotools syntax error with ax_check_compile_flag

From Dev

How to compile Spring Boot applications with Java 8 --parameter flag

From Dev

Cannot compile modules unless the --module flag is provided

From Dev

Cannot compile modules unless the '--module' flag is provided

From Dev

Typescript - "Cannot compile modules unless the '--module' flag is provided."

From Dev

How to compile an executable using clang and safe-stack flag

From Dev

Compile and link Fortran and C with ifort and icc

From Dev

Cannot compile namespaces when the '--isolatedModules' flag is provided

From Dev

How to get Nsight EE to compile with -dc flag?

From Dev

"Recompile with -fPIC" error persists even after adding -fPIC compile flag

From Dev

Controller, Directive-Controller, Compile, Link - Workflow (Compile function not working)

From Dev

clang: error: unsupported option '-fopenmp' with compile spams-python lib

From Dev

compile c++ code with and without fopenmp flag

From Dev

What library needs to be installed for -lz compile flag

From Dev

ng-repeat with compile or link?

From Dev

Add /MT compile flag to project

From Dev

Compile R package with `-static` flag

From Dev

Cannot compile modules unless the '--module' flag is provided

From Dev

What library needs to be installed for -lz compile flag

From Dev

How to set "Other LInk Flag"?

From Dev

How to check in Makefile that gcc supports -fopenmp-simd flag?

Related Related

  1. 1

    Link error during gcc compile with makefile

  2. 2

    Link and compile an assembly function

  3. 3

    Compile with standalone flag gives compilation errors in client code

  4. 4

    Angular JS Directive - Template, compile or link?

  5. 5

    how to override -DNDEBUG compile flag when building cython module

  6. 6

    Make: just link, skip compile

  7. 7

    How do I compile and link unit tests?

  8. 8

    How to compile and link against cddlib library?

  9. 9

    autotools syntax error with ax_check_compile_flag

  10. 10

    How to compile Spring Boot applications with Java 8 --parameter flag

  11. 11

    Cannot compile modules unless the --module flag is provided

  12. 12

    Cannot compile modules unless the '--module' flag is provided

  13. 13

    Typescript - "Cannot compile modules unless the '--module' flag is provided."

  14. 14

    How to compile an executable using clang and safe-stack flag

  15. 15

    Compile and link Fortran and C with ifort and icc

  16. 16

    Cannot compile namespaces when the '--isolatedModules' flag is provided

  17. 17

    How to get Nsight EE to compile with -dc flag?

  18. 18

    "Recompile with -fPIC" error persists even after adding -fPIC compile flag

  19. 19

    Controller, Directive-Controller, Compile, Link - Workflow (Compile function not working)

  20. 20

    clang: error: unsupported option '-fopenmp' with compile spams-python lib

  21. 21

    compile c++ code with and without fopenmp flag

  22. 22

    What library needs to be installed for -lz compile flag

  23. 23

    ng-repeat with compile or link?

  24. 24

    Add /MT compile flag to project

  25. 25

    Compile R package with `-static` flag

  26. 26

    Cannot compile modules unless the '--module' flag is provided

  27. 27

    What library needs to be installed for -lz compile flag

  28. 28

    How to set "Other LInk Flag"?

  29. 29

    How to check in Makefile that gcc supports -fopenmp-simd flag?

HotTag

Archive