Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Numerical Recipes Third Edition Forum > General Problems in Using NR3

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-20-2010, 07:23 PM
kirill_igum kirill_igum is offline
Registered User
 
Join Date: Aug 2008
Posts: 3
Dopr853 multiple definition linking error

Hi, i'm using NR3(c++) to solve ode using rkDopr853 method

i call integration in bratoket.cc:
Code:
Output out(duration-1);
rhs_corr d(x0); 
Odeint<StepperDopr853<rhs_corr> > ode(ystart,x1,x2,atol,rtol,h1,hmin,out,d);
ode.integrate();
bratoket.h contains:
Code:
#include "nr3.h" 
#include "stepper.h" 
#include "odeint.h" 
#include "stepperdopr853.h"
no other file contains
Code:
#include "stepperdopr853.h"
when i link all the .o files, i get errors like this one
Code:
...
bratoket.o:(.rodata+0xa18): multiple definition of `Dopr853_constants::d76'
main.o:(.rodata+0x480): first defined here
bratoket.o:(.rodata+0xa20): multiple definition of `Dopr853_constants::d77'
main.o:(.rodata+0x488): first defined here
bratoket.o:(.rodata+0xa28): multiple definition of `Dopr853_constants::d78'
main.o:(.rodata+0x490): first defined here
bratoket.o:(.rodata+0xa30): multiple definition of `Dopr853_constants::d79'
main.o:(.rodata+0x498): first defined here
bratoket.o:(.rodata+0xa38): multiple definition of `Dopr853_constants::d710'
main.o:(.rodata+0x4a0): first defined here
bratoket.o:(.rodata+0xa40): multiple definition of `Dopr853_constants::d711'
main.o:(.rodata+0x4a8): first defined here
bratoket.o:(.rodata+0xa48): multiple definition of `Dopr853_constants::d712'
main.o:(.rodata+0x4b0): first defined here
bratoket.o:(.rodata+0xa50): multiple definition of `Dopr853_constants::d713'
main.o:(.rodata+0x4b8): first defined here
bratoket.o:(.rodata+0xa58): multiple definition of `Dopr853_constants::d714'
main.o:(.rodata+0x4c0): first defined here
bratoket.o:(.rodata+0xa60): multiple definition of `Dopr853_constants::d715'
main.o:(.rodata+0x4c8): first defined here
bratoket.o:(.rodata+0xa68): multiple definition of `Dopr853_constants::d716'
main.o:(.rodata+0x4d0): first defined here
make: *** [main] Error 1
errors come up for all dopr853 constants and other files between main and bratoket.

the errors don't come up if i use StepperBS or StepperDopr5. the errors also don't come up if i make the whole program with dopr5 and then change to dopr853 in the bratoket.h and .cc files and then make again.

putiing #ifndef ... doesn't help

can someone c a solution?

--Kirill
Reply With Quote
  #2  
Old 06-21-2010, 08:09 AM
davekw7x davekw7x is offline
Registered User
 
Join Date: Jan 2008
Posts: 368
Quote:
Originally Posted by kirill_igum View Post
...no other file contains
Code:
#include "stepperdopr853.h"
Do you have a header file that includes stepperdopr853.h? Is that header included from more than one .cc file? (For example: Does bratoket.h include stepperdopr853.h and is bratoket.h included in more than one of your .cc files?)

Quote:
Originally Posted by kirill_igum
#ifndef ... doesn't help
That won't protect against including the same header file from other .cc files.

Each .cc file is compiled separately and a symbol table is created for that object file. When the linker puts all of the object files together it merges the symbol tables. If the same symbol is defined in more than one of the object file tables, the linker reports an error and no executable can be created.


Bottom line: With files from the Numerical Recipes Version 3 distribution you can't include header files like stepperdopr853.h from more than one .cc file since the header file actually declares memory storage.

It "just happens" that, since stepperdopr5.h just consists of some templates and doesn't contain any data definitions that would result in problems like this, you actually can get away with including it from more than one .cc file. But that's not true for many other NR3 header files.


If you are wondering why the package was put together that way:

See responses from one of the authors here: http://www.nr.com/forum/showthread.php?t=1332 and here: http://www.nr.com/forum/showthread.php?t=1260


Regards,

Dave

Last edited by davekw7x; 06-21-2010 at 12:19 PM.
Reply With Quote
Reply

Tags
dopr853, ode

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 07:35 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.