Makefile : problems using -fopenmp

General OpenMP discussion

Makefile : problems using -fopenmp

Postby alessandro » Tue Jun 11, 2013 5:07 am

OS: Xubuntu 12.04
$ gcc -v
gcc version 4.6.3
Code: Select all

makefile
#---------------------------------
# Set correct variables and paths
#---------------------------------
OS := $(shell uname)
CC = g++
CFLAGS=-o -fopenmp
ifeq ($(OS),GNU/kFreeBSD)
OS = Linux
endif


#-----------------------------------------------
# Set compilation flags for customizing build
#-----------------------------------------------
#Using the follow comment lines from the prompt work:
#g++  test1-forum.cpp -o test1-forum.o -fopenmp
# ./test1-forum.o
all: test1-forum.cpp
echo "Done"
test1:test1-forum.cpp
$(CC) $(CFLAGS) test1-forum test1-forum.cpp


Code: Select all
#ifdef _OPENMP
   #include <omp.h>
#endif /* _OPENMP */
#include <iostream>
int main()
{
   int nthreads=0;
   #ifdef _OPENMP
      nthreads=omp_get_max_threads();
   #endif /* _OPENMP */
   
   std::cout << "Default number of automatic threads for the Pc: " << omp_get_max_threads() <<"\n";
  //...
}

$ make test1-forum
Code: Select all
g++     test1-forum.cpp   -o test1-forum
test1-forum.cpp: In function ‘int main()’:
test1-forum.cpp:12:91: error: ‘omp_get_max_threads’ was not declared in this scope
make: *** [test1-forum] Errore 1

I add the ifdef mainly for check that the problem is due to the non-recognition of the passage of fopen.
I already read documentations but for though it may be trivial to most experts I can't solve this problem.
Someone could help to resolve this issue?
alessandro
 
Posts: 26
Joined: Tue Jun 11, 2013 2:14 am

Re: Makefile : problems using -fopenmp

Postby ftinetti » Tue Jun 11, 2013 5:41 am

Hi,

The problem is in the Makefile, since the compile-link line actually run is
g++ test1-forum.cpp -o test1-forum

and it should be
Code: Select all
g++  -fopenmp   test1-forum.cpp   -o test1-forum

(with which your code compiles and links fine). I'm not an expert in Makefiles, but the current one does not seem to do what you expect, since if you comment the compiler line as
Code: Select all
#      $(CC) $(CFLAGS) test1-forum test1-forum.cpp

you'll find the command line run is exactly the same, i.e.

Code: Select all
$ cat Makefile
#---------------------------------
# Set correct variables and paths
#---------------------------------
OS := $(shell uname)
CC = g++
CFLAGS = -o -fopenmp
ifeq ($(OS),GNU/kFreeBSD)
OS = Linux
endif


#-----------------------------------------------
# Set compilation flags for customizing build
#-----------------------------------------------
#Using the follow comment lines from the prompt work:
#g++  test1-forum.cpp -o test1-forum.o -fopenmp
# ./test1-forum.o
all: test1-forum.cpp
        echo "Done"

test1: test1-forum.cpp
#       $(CC) $(CFLAGS) test1-forum test1-forum.cpp
$
$
$ make test1-forum
g++     test1-forum.cpp   -o test1-forum
test1-forum.cpp: In function ‘int main()’:
test1-forum.cpp:14: error: ‘omp_get_max_threads’ was not declared in this scope
make: *** [test1-forum] Error 1


HTH,

Fernando.
ftinetti
 
Posts: 558
Joined: Wed Feb 10, 2010 2:44 pm

Re: Makefile : problems using -fopenmp

Postby MarkB » Tue Jun 11, 2013 6:59 am

You can get more sophisticated with makefiles, but for starters, try this:

Code: Select all
CC = g++
CFLAGS = -fopenmp
LDFLAGS = -fopenmp

all:    test1
        echo "Done"
test1:  test1-forum.o
        $(CC) $(LDFLAGS) -o test1-forum test1-forum.o

.cpp.o:
        $(CC) $(CFLAGS) -c $<

MarkB
 
Posts: 408
Joined: Thu Jan 08, 2009 10:12 am

Re: Makefile : problems using -fopenmp

Postby alessandro » Tue Jun 11, 2013 9:07 am

MarkB using your version i obtain that error:

$ make test1-forum
Code: Select all
cc   test1-forum.o   -o test1-forum
test1-forum.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.text+0x0): first defined here
test1-forum.o:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.rodata+0x0): first defined here
test1-forum.o: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o:(.fini+0x0): first defined here
test1-forum.o:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
test1-forum.o: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.data+0x0): first defined here
test1-forum.o: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i686-linux-gnu/4.6/crtbegin.o:(.data+0x0): first defined here
test1-forum.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/i686-linux-gnu/4.6/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
test1-forum.o:(.dtors+0x4): first defined here
/usr/bin/ld: error in test1-forum.o(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status
make: *** [test1-forum] Errore 1
alessandro
 
Posts: 26
Joined: Tue Jun 11, 2013 2:14 am

Re: Makefile : problems using -fopenmp

Postby MarkB » Tue Jun 11, 2013 9:15 am

test1-forum is not a target in my makefile (as it wasn't in yours!). Try typing

make all

or just

make


If you want the target to be called test1-forum, then replace

test1: test1-forum.o

with

test1-forum: test1-forum.o
MarkB
 
Posts: 408
Joined: Thu Jan 08, 2009 10:12 am

Re: Makefile : problems using -fopenmp

Postby alessandro » Tue Jun 11, 2013 10:58 am

$ make
Code: Select all
make: *** Nessun obiettivo specificato e nessun makefile trovato.  Arresto.


$ make all
Code: Select all
make: ***  Nessuna regola per generare l'obiettivo "all".  Arresto.


While changing:
test1: test1-forum.o
with
test1-forum: test1-forum.o
on the make file i obtain the same error as before:
$ make test1-forum
Code: Select all
cc   test1-forum.o   -o test1-forum
test1-forum.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.text+0x0): first defined here
test1-forum.o:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.rodata+0x0): first defined here
test1-forum.o: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o:(.fini+0x0): first defined here
test1-forum.o:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
test1-forum.o: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o:(.data+0x0): first defined here
test1-forum.o: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i686-linux-gnu/4.6/crtbegin.o:(.data+0x0): first defined here
test1-forum.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/i686-linux-gnu/4.6/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
test1-forum.o:(.dtors+0x4): first defined here
/usr/bin/ld: error in test1-forum.o(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status
make: *** [test1-forum] Errore 1
alessandro
 
Posts: 26
Joined: Tue Jun 11, 2013 2:14 am

Re: Makefile : problems using -fopenmp

Postby MarkB » Tue Jun 11, 2013 11:24 am

Your makefile needs to be named makefile (or Makefile). Or use make -f <makefilename>
MarkB
 
Posts: 408
Joined: Thu Jan 08, 2009 10:12 am

Re: Makefile : problems using -fopenmp

Postby alessandro » Tue Jun 11, 2013 11:40 am

After that change i obtain that error:
$ make
makefile:6: *** separatore (era inteso TAB invece di 8 spazi?) mancante. Arresto.
$ make all
makefile:6: *** separatore (era inteso TAB invece di 8 spazi?) mancante. Arresto.
$ make test1-forum
makefile:6: *** separatore (era inteso TAB invece di 8 spazi?) mancante. Arresto.
alessandro
 
Posts: 26
Joined: Tue Jun 11, 2013 2:14 am

Re: Makefile : problems using -fopenmp

Postby MarkB » Tue Jun 11, 2013 12:09 pm

The command lines (i.e. the ones with $(CC) in them) must start with a TAB character, not spaces.

Can I suggest you take a look at a introduction to using make, such as http://capone.mtsu.edu/csdept/Facilitie ... s/make.htm ?
MarkB
 
Posts: 408
Joined: Thu Jan 08, 2009 10:12 am

Re: Makefile : problems using -fopenmp

Postby alessandro » Tue Jun 11, 2013 12:47 pm

Now i read it but I still do not understand ...
I removed all the initial space on the make:
Code: Select all
CC = g++
CFLAGS = -fopenmp
LDFLAGS = -fopenmp

all:test1-forum
echo "Done"
test1-forum:test1-forum.o
$(CC) $(LDFLAGS) -o test1-forum test1-forum.o

.cpp.o:
$(CC) $(CFLAGS) -c $<

without result.
I tried to put \t before the $(CC) ... line.
Nothing.
alessandro
 
Posts: 26
Joined: Tue Jun 11, 2013 2:14 am

Next

Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 7 guests

cron