multiple-definition-error

Strange multiple definition error

拥有回忆 提交于 2019-12-25 01:49:56
问题 vio@!@#$:~/cpp/OOP/6$ g++ -o main main.o NormalAccount.o HighCreditAccount.o Account.o AccountHandler.o AccountHandler.o:(.bss+0x0): multiple definition of `AccountHandler::account_number' main.o:(.bss+0x0): first defined here collect2: ld returned 1 exit status I got the error message above. But I couldn't find the code where it is multiply defined, so I changed all account_number to number_of_account in 'account.h' and 'AccountHandler.cpp' and vio@!@#$:~/cpp/OOP/6$ vi AccountHandler.cpp vio

Multiple definition of lots of std:: functions when linking

人走茶凉 提交于 2019-12-24 22:35:14
问题 I am trying to integrate some external code into my application. My code was pure C, but the new code is C++, so I simply renamed my C files to .cc and compiled the whole thing with g++. It compiles fine, but I get a crapton of link errors : CMakeFiles/svrt.dir/svrtH_generator.cc.o: In function `operator new(unsigned long, void*)': svrtH_generator.cc:(.text+0x0): multiple definition of `operator new(unsigned long, void*)' CMakeFiles/svrt.dir/svrt_generator.cc.o:svrt_generator.cc:(.text+0x0):

Multiple definitions error: one in my file and one in the moc file.

筅森魡賤 提交于 2019-12-22 04:47:18
问题 I have a class called FindAndReplaceBar, whose implementation is this: #include "FindAndReplaceBar.h" #include <QLabel> #include <QPushButton> #include <QGridLayout> #include <QTextDocument> #include <QLineEdit> FindAndReplaceBar::FindAndReplaceBar(QObject *parent) : QToolBar(NULL) { lblFind = new QLabel("Find: ",this); lblReplace = new QLabel("Replace",this); ledtFind = new QLineEdit(this); ledtReplace = new QLineEdit(this); QPixmap next(":/res/resources/next.gif"); QPixmap previous(":/res

Namespace error while declare it in global scope

旧街凉风 提交于 2019-12-12 16:43:59
问题 I have 3 files Test.h , Test.cpp and main.cpp Test.h #ifndef Test_H #define Test_H namespace v { int g = 9;; } class namespce { public: namespce(void); public: ~namespce(void); }; #endif Test.cpp #include "Test.h" namespce::namespce(void) { } namespce::~namespce(void) { } Main.cpp #include <iostream> using namespace std; #include "Test.h" //#include "namespce.h" int main () { return 0; } during building it gives the following error .. 1>namespce.obj : error LNK2005: "int v::g" (?g@v@@3HA)

code guards fail

北慕城南 提交于 2019-12-11 08:59:19
问题 Take this files: a.h #ifndef A_H #define A_H char EL[] = "el"; #endif a.cpp #include "a.h" b.h #ifndef B_H #define B_H #include "a.h" #endif b.cpp #include "b.h" main.cpp #include "b.h" #include "a.h" int main() { } This is only an example, but I've really this problem: g++ -c a.cpp g++ -c b.cpp g++ -c main.cpp g++ -o main main.o a.o b.o a.o:(.data+0x0): multiple definition of `EL' main.o:(.data+0x0): first defined here b.o:(.data+0x0): multiple definition of `EL' main.o:(.data+0x0): first

Same symbols in different libraries and linking order

有些话、适合烂在心里 提交于 2019-12-10 15:41:13
问题 I have 2 libraries: test.1 and test.2 . Both libraries contain a single global extern "C" void f(); function, with different implementations (just a cout for the test). I did the following test: Test 1 Dynamic linking: If I add libtest.1.so and then libtest.2.so in the makefile of the executable and then call f(); in main , libtest.1.so->f() is called. If I change the order in the makefile, libtest.2.so->f() is called Test 2 Static linking: Absolutely the same happens with static libraries

How to avoid multiple definition linking error?

前提是你 提交于 2019-12-05 03:33:42
Beside moving the hello() function into another source (.cpp) file or renaming the function. Is there any other methods to avoid the linking error? staticLibA.h #ifndef _STATIC_LIBA_HEADER #define _STATIC_LIBA_HEADER int hello(void); int hello_staticLibA_only(void); #endif staticLibA.cpp #include "staticLibA.h" int hello(void) { printf("\nI'm in staticLibA\n"); return 0; } int hello_staticLibA_only(void) { printf("\nstaticLibA: hello_staticLibA_only\n"); return 0; } output: g++ -c -Wall -fPIC -m32 -o staticLibA.o staticLibA.cpp ar -cvq ../libstaticLibA.a staticLibA.o a - staticLibA.o

C++: Multiple definition error for global functions in the header file

£可爱£侵袭症+ 提交于 2019-12-04 16:00:07
问题 This function is global and is defined in the header file ( temporarily I want to keep it there). The header file also constitutes a particular class which has inline functions and one of those functions call this global function. The source file doesn't contain any occurrences of the global function in question. Any hints on cause of the error? I can post the code if anyone is interested. mainwindow.o: In function `tileForCoordinate(double, double, int)': mainwindow.cpp:(.text+0x310):

Multiple definition of main()

扶醉桌前 提交于 2019-12-04 05:08:27
问题 Hi guys trying to use two main() and getting this error multiple definition of main(). I renamed my main functions then why is this error and also first defined here for my print(). header file: #ifndef TOP_H_ #define TOP_H_ #include <stdio.h> #include <string.h> #define onemain main #define twomain main inline void print(); #endif /* TOP_H_ */ c file one: #include "top.h" void print(); int onemain() { print(); return 0; } void print() { printf("hello one"); } c file two: #include "top.h"

Multiple definition of main()

江枫思渺然 提交于 2019-12-02 06:02:45
Hi guys trying to use two main() and getting this error multiple definition of main(). I renamed my main functions then why is this error and also first defined here for my print(). header file: #ifndef TOP_H_ #define TOP_H_ #include <stdio.h> #include <string.h> #define onemain main #define twomain main inline void print(); #endif /* TOP_H_ */ c file one: #include "top.h" void print(); int onemain() { print(); return 0; } void print() { printf("hello one"); } c file two: #include "top.h" void print(); int twomain() { print(); return 0; } void print() { printf("hello two"); } Basically any C