Solved

Cant compile using g++ -O2 or -O3

Posted on 2008-06-14
2
1,145 Views
Last Modified: 2013-12-14
Hi

I can run my code using O mode but when I try to use the compilers advanced optimization settings I get whole load of funny errors.  Any suggestions?

Thanks

Niall
This isn't all of the errors, just the first few!
 
 

pclxb10>make

g++ -o2 csvdemo main.cpp csvparser.cpp

csvdemo: In function `_start':

(.text+0x0): multiple definition of `_start'

/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o:(.text+0x0): first defined here

csvdemo:(.rodata+0x0): multiple definition of `_fp_hw'

/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o:(.rodata+0x0): first defined here

csvdemo: In function `_fini':

(.fini+0x0): multiple definition of `_fini'

/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o:(.fini+0x0): first defined here

csvdemo:(.rodata+0x4): multiple definition of `_IO_stdin_used'

/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o:(.rodata.cst4+0x0): first defined here

csvdemo: In function `__data_start':

(.data+0x0): multiple definition of `__data_start'

/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o:(.data+0x0): first defined here

csvdemo:(.rodata+0x8): multiple definition of `__dso_handle'

/usr/lib/gcc/i386-redhat-linux/4.1.2/crtbegin.o:(.rodata+0x0): first defined here

csvdemo: In function `_init':

Open in new window

0
Comment
Question by:duncan54747
  • 2
2 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 21787705
>> g++ -o2 csvdemo main.cpp csvparser.cpp

Did you mean :

        g++ -o csvdemo main.cpp csvparser.cpp -O2

The -o flag is for renaming the executable (to csvdemo in this case).
The -O2 flag sets the optimization level (notice the upper case O).
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21787709
The reason for all those errors, is because the compiler compiled the two .cpp files, and then the linker tried to link them together with the csvdemo executable that was there from an earlier build. Obviously these contain the exact same symbols.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now