lee_timmy Posted October 31, 2012 Report Share Posted October 31, 2012 Hi, all I tried to implement the time domain Gaussian random noise in page 93 of AMS user manual. I made this as an sub-module of the BASK modulation/demodulation system. However, the compilation gives me errors: Gnoise.o: In function `gauss_rand(double)': Gnoise.cpp:(.text+0x60): multiple definition of `gauss_rand(double)' BASK.o:BASK.cpp:(.text+0x60): first defined here /tmp/ccRJX6KO.o: In function `gauss_rand(double)': test_BASK.cpp:(.text+0x60): multiple definition of `gauss_rand(double)' BASK.o:BASK.cpp:(.text+0x60): first defined here collect2: ld returned 1 exit status make: *** [test_BASK] Error 1 It says the the C++ function gauss_rand(double) is defined in multiple places. But I'm sure that's Gnoise.cpp is the only file where I use and define this function. How can SystemC/AMS call a C++ function in a module without getting this error? Thank you! Tim Quote Link to comment Share on other sites More sharing options...
sumit_tuwien Posted October 31, 2012 Report Share Posted October 31, 2012 Dear Timmy, Most possibly you are missing some compiler guards. Guard your code using something like as follows : # ifndef GAUSSIAN_RANDOM_H_ # define GAUSSIAN_RANDOM_H_ // your declaration goes here # endif Regards, Sumit Quote Link to comment Share on other sites More sharing options...
apfitch Posted October 31, 2012 Report Share Posted October 31, 2012 Dear Timmy, Most possibly you are missing some compiler guards. Guard your code using something like as follows : # ifndef GAUSSIAN_RANDOM_H_ # define GAUSSIAN_RANDOM_H_ // your declaration goes here # endif Regards, Sumit Hi Sumit, header guards won't necessarily help. They stop two header files being included sequentially - but if you have a function *body* in the header, and include that header in two independent files, you'll still get multiple definitions at link time. My guess is that Timmy is #including a gnoise.cpp. In that case the fix is to make a gnoise.h with the function prototype, with your header guards of course, and include the .h not the .cpp, regards Alan Philipp A Hartmann, sumit_tuwien and maehne 3 Quote Link to comment Share on other sites More sharing options...
sumit_tuwien Posted October 31, 2012 Report Share Posted October 31, 2012 @Alan : jouk - my life is so wasted Quote Link to comment Share on other sites More sharing options...
lee_timmy Posted November 1, 2012 Author Report Share Posted November 1, 2012 Thanks, Alan. You are correct. I separated my Gnoise.cpp to a Gnoise.h with the function prototype, and Gnoise.cpp only having the function of sc_processing. The C++ function "gauss_rand(double)" is called in Gnoise.cpp. In this way, Gnoise.h can be included in its top module. The compilation is passed and simulation seems correct. Thank you all! Tim Hi Sumit, header guards won't necessarily help. They stop two header files being included sequentially - but if you have a function *body* in the header, and include that header in two independent files, you'll still get multiple definitions at link time. My guess is that Timmy is #including a gnoise.cpp. In that case the fix is to make a gnoise.h with the function prototype, with your header guards of course, and include the .h not the .cpp, regards Alan Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.