Compile Error Redefinition
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings error redefinition of typedef and policies of this site About Us Learn more about Stack Overflow error redefinition of typedef 'gliststore' the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags
Error Redefinition Of 'class
Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only
Error Redefinition Of ‘class
takes a minute: Sign up GCC compiler error: “redefinition…previously defined” up vote 7 down vote favorite 3 I'm getting a lot of " redefinition of x....x previously defined here". Please what does this error means? c++ gcc compiler-construction share|improve this question asked Apr 2 '09 at 1:00 caesar add a comment| 3 Answers 3 active oldest votes up vote 20 error redefinition of c++ down vote You need to limit each file from being included only once. You can do this in 2 ways. 1) At the top of your header files put: #pragma once Or 2) if your compiler doesn't support that, put at the top/end of your header files: #ifndef _MYFILE_H_ #define _MYFILE_H_ ... #endif Replace MYFILE with the name of your file, and replace ... with the contents of the header file. share|improve this answer edited Apr 2 '09 at 7:11 unwind 254k38330460 answered Apr 2 '09 at 1:18 Brian R. Bondy 197k82473571 1 I think that #pragma only works in VC++, not in gcc. The #define trick is portable. –Gorpik Apr 2 '09 at 7:19 supoprted by gcc and vc++ –Brian R. Bondy Apr 2 '09 at 10:29 Wikipedia says #pragma once is supported by VC++ and gcc en.wikipedia.org/wiki/Pragma_once . –Max Lybbert Apr 3 '09 at 20:48 #pragma works fine with gcc.. I'm using it at this very moment after I reading about it and it solved a ton of errors! –mmoment
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more
Error Redefinition Of ‘struct
about Stack Overflow the company Business Learn more about hiring developers or posting ads error redefinition of 'struct iovec' with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow error redefinition of default argument is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Redefinition errors in .h files up vote 6 down vote favorite //list.h http://stackoverflow.com/questions/707920/gcc-compiler-error-redefinition-previously-defined file typedef struct _lnode{ struct _lnode *next; size_t row; size_t column; short data; }lnode; typedef struct _llist{ struct _lnode *head; size_t size; }llist; //matrix.h file typedef struct _matrix{ size_t width; size_t height; size_t k; int **data; }matrix; //smatrix.h file #include "list.h" #include "matrix.h" typedef struct _smatrix{ size_t width; size_t height; size_t k; llist data; }smatrix; smatrix* make_smatrix(matrix *m); smatrix.h file includes list.h file and matrix.h files. If I include http://stackoverflow.com/questions/5430019/redefinition-errors-in-h-files those header files in smatrix.h file then I get redefinition of 'lnode'. redefinition of '_llist' and redefinition of '_matrix' errors. If I took those heder files our from smatrix.h file then the error went away but it complains about matrix type in the function parameter. I want to call functions defined in list.h and matrix.h files in smatrix.c file.. What do I do? Thanks in advance.. c share|improve this question edited Apr 29 '15 at 17:48 BartoszKP 22.3k84067 asked Mar 25 '11 at 8:18 LCYSoft 3,2791160116 add a comment| 4 Answers 4 active oldest votes up vote 12 down vote accepted Possible problem of multiple inclusions. Try to guard your header files with file list.h #ifndef _LISTH_ #define _LISTH_
Support Search GitHub This repository Watch 425 Star https://github.com/phpredis/phpredis/issues/323 4,281 Fork 1,287 phpredis/phpredis Code Issues 243 Pull requests 37 Projects 0 Pulse Graphs New issue Compilation error: redefinition of parameter ‘tsrm_ls’ #323 http://www.cplusplus.com/forum/beginner/4915/ Closed shouze opened this Issue Mar 28, 2013 · 7 comments Projects None yet Labels None yet Milestone No milestone Assignees No one error redefinition assigned 4 participants shouze commented Mar 28, 2013 Due to last day commit compilation is broken under ubuntu at leas with the following php version: PHP 5.3.22 (cli) (built: Mar 14 2013 11:37:20) Copyright (c) 1997-2013 The PHP Group Compilation error: make /bin/bash /home/travis/phpredis/libtool --mode=compile cc error redefinition of -I. -I/home/travis/phpredis -DPHP_ATOM_INC -I/home/travis/phpredis/include -I/home/travis/phpredis/main -I/home/travis/phpredis -I/home/travis/.phpenv/versions/5.3.22/include/php -I/home/travis/.phpenv/versions/5.3.22/include/php/main -I/home/travis/.phpenv/versions/5.3.22/include/php/TSRM -I/home/travis/.phpenv/versions/5.3.22/include/php/Zend -I/home/travis/.phpenv/versions/5.3.22/include/php/ext -I/home/travis/.phpenv/versions/5.3.22/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/travis/phpredis/redis.c -o redis.lo cc -I. -I/home/travis/phpredis -DPHP_ATOM_INC -I/home/travis/phpredis/include -I/home/travis/phpredis/main -I/home/travis/phpredis -I/home/travis/.phpenv/versions/5.3.22/include/php -I/home/travis/.phpenv/versions/5.3.22/include/php/main -I/home/travis/.phpenv/versions/5.3.22/include/php/TSRM -I/home/travis/.phpenv/versions/5.3.22/include/php/Zend -I/home/travis/.phpenv/versions/5.3.22/include/php/ext -I/home/travis/.phpenv/versions/5.3.22/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/travis/phpredis/redis.c -fPIC -DPIC -o .libs/redis.o /home/travis/phpredis/redis.c:401:73: error: redefinition of parameter ‘tsrm_ls’ /home/travis/phpredis/redis.c:401:44: note: previous definition of ‘tsrm_ls’ was here phpredis member michael-grunder commented Mar 28, 2013 Hey there, can you please try it now? :) Cheers, Mike michael-grunder closed this Mar 28, 2013 shouze commented Mar 28, 2013 Thank you Mike, works like a charm! Cheers, Sébastien willsky commented Sep 6, 2013 Compilation error, ubuntu12.04(server) php5.5.3(from release tag) $php -v PHP 5.5.3 (cli) (built: Sep 7 2013 03:01:00) (DEBUG) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies $make /bin/bash /home/will/Download/phpredis/libtool --mode=compile cc -I. -I/home/will/Download/phpredis -
}; Integer.cpp 1
2
3
4
5
#include "Object.cpp" class Integer : public Object { }; Boolean.cpp 1
2
3
4
5
#include "Object.cpp" class Boolean : public Object { }; Main.cpp 1
2
3
4
5
6
7
8
9
#include "Integer.cpp" #include "Object.cpp" int main() { Integer i; Boolean b; return 0; } When i compile the project i get error as error C2011: 'Object' : 'class' type redefinition Now, in Main.cpp file i make use of both Integer and Boolean so isn't including this files valid? help appreciated amal Oct 17, 2008 at 8:42am UTC guestgulkan (2942) Yes you will get C2011: 'Object' : 'class' type redefinition error. This is because main.cpp line 1 - includes interger.cpp which itself includes object.cpp. and on line 2 there is include object.cpp So object cpp gets included twice which means that class Object is seen twice by the compiler - hence the error. The way you are including cpp files is not the recommended way of doing things. Class declarations are usually put into header files. The code for the class is put into the cpp file. The header file should have a header guard to prevent multiple inclusion errors. Example of header guard object.h 1
2
3
4
5
6
7
8
//header guard at start of header file #ifndef OBJECT_H #define OBJECT_H class Object { }; //End guard at bottom of header file #endif Do something similar for the other class declaration files; integer.h 1
2
3
4
5
6
7
8
#ifndef INTEGER_H #define INTEGER_H #include "Object.h" class Integer : public Object { }; #endif boolean.h 1
2
3
4
5
6
7
8
9
#ifndef BOOLEAN_H #define BOOLEAN_H #include "Object.h" class Boolean : public Object { }; #endif Then in main.cpp you will have: 1
2
3
4
5
6
7
8
9
10
#include "Integer.h" #include "Object.h" //probably won't need this line #include boolean.h int main() { Integer i; Boolean b; return 0; } Oct 17, 2008 at 10:09am UTC amalshah71 (15)