Solved

Cant compile using g++ -O2 or -O3

Posted on 2008-06-14
2
1,158 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
object oriented programming comparison 5 77
VS2015 Redefinition errors 4 73
CD-RW/DVD-ROM DRIVE 3 59
software inventory tools 3 42
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

807 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