Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compiling source code on 2 different versions of gcc

Tags:

c

gcc

I am compiling my source code on 2 different machines that use different versions of gcc.

cflags c89

-Wall -Wextra -Wunreachable-code -g -m32 -D_DEBUG -O0 -D_LARGEFILE64_SOURCE -D_REETRANT -D_THREAD_SAFE

One is redhat-4

gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46)
Linux 203_test_server 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

And one is Fedora 18

gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
Linux localhost.localdomain 3.8.1-201.fc18.x86_64 #1 SMP Thu Feb 28 19:23:08 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

My fedora 18 compiles with no errors. However, on the redhat 4 machine I get some errors.

channel.h:35: error: redefinition of typedef ‘channel_t’
internal.h:19: error: previous declaration of ‘channel_t’ was here

I think the error is just a circular problem. However, with the same code base would compiling on 2 different machines really make a difference using 2 different versions of gcc?

I was thinking using a newer version of a compiler will generate more errors, as the newer compiler might be more strict.

This is not a question to solve the error, but a general question on compilers.

Is there any flags I can set to avoid this in the future. Maybe if compiling on this version of gcc do this, if the versions are not compatible?

like image 233
ant2009 Avatar asked Mar 05 '13 11:03

ant2009


People also ask

Can I have multiple versions of gcc?

With GCC compilers installed, we can now proceed to install multiple versions of G++ compilers. Alternatively, you can install both GCC and G++ compilers with a single command, as shown below.

Is G ++ and gcc the same?

“GCC” is a common shorthand term for the GNU Compiler Collection. This is both the most general name for the compiler, and the name used when the emphasis is on compiling C programs (as the abbreviation formerly stood for “GNU C Compiler”). When referring to C++ compilation, it is usual to call the compiler “G++”.

Is gcc compiled with gcc?

Note that gcc has a policy that gcc major version X can always be compiled with gcc major version X-1, so any new features added to the compiler in X can only be used in the gcc source itself from X+1.

What is G ++ compiler?

g++ command is a GNU c++ compiler invocation command, which is used for preprocessing, compilation, assembly and linking of source code to generate an executable file. The different “options” of g++ command allow us to stop this process at the intermediate stage.


2 Answers

It would depend on what headers are being included by the source code. If you're linking to external libraries, it may be that your source code is incompatible with the version of a library installed on the older system.

If the source code doesn't include any external library headers (except the C library) then there may be preprocessor directives that need changing.

EDIT:

After a Google search, it appears that channel_t is from a kernel header. You're using kernel releases far apart on the two machines. If the code depends on a kernel header file, it may well require a kernel version newer than on the Red Hat machine. You haven't specified what the code is (is it a device driver?), or what files it's including, so it's difficult to say more.

like image 130
teppic Avatar answered Oct 19 '22 16:10

teppic


That's a duplicate of: Why "Redefinition of typedef" error with GCC 4.3 but not GCC 4.6?

The answer is that gcc was changed to modify this check.

http://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=ce3765bf44e49ef0568a1ad4a0b7f807591d6412

Sometimes, warnings for behavior defined in the language, but considered bad practice, are considered too strict because certain useful and/or harmless use cases are included in the warning. Compiler developers then try to fix in the opposite way, that is, reducing the amount of warnings. In this case, the change made the warning appear only when the second definition changed the typedef to a different, but compatible type.

Other current example is -Wshadow in gcc 4.8 just announced. In the release note, it says that -Wshadow won't warn anymore if a function name is shadowed by another.

See: http://gcc.gnu.org/gcc-4.8/changes.html

Edit: how you can avoid this: either delete one of the definitions, or move it to a separate include file and delete both other definitions.

like image 35
hdante Avatar answered Oct 19 '22 15:10

hdante