ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've been working at learning how to write makefiles and I'm a bit stuck. I've got a fairly simple project that will eventually be a framework for TCP/IP Communications in evolutionary algorithms that I've been using Eclipse to develop. For personal development I want to learn how to write makefiles by hand but have gotten kind of stuck Here is the makefile as it stands now:
Port and Mailbox are a virtual class and a template class respectively. I get these errors when I run make:
Code:
connection.o: In function `Connection::ThreadStart(void*)':
Connection.cxx:(.text+0x0): multiple definition of `Connection::ThreadStart(void*)'
connection.o:Connection.cxx:(.text+0x0): first defined here
connection.o: In function `Connection::TransmitData(char const*, int)':
Connection.cxx:(.text+0x20): multiple definition of `Connection::TransmitData(char const*, int)'
connection.o:Connection.cxx:(.text+0x20): first defined here
connection.o: In function `Connection::IsActive()':
Connection.cxx:(.text+0x4e): multiple definition of `Connection::IsActive()'
connection.o:Connection.cxx:(.text+0x4e): first defined here
connection.o: In function `Connection::GetConnectedHostIdentifier()':
Connection.cxx:(.text+0x5e): multiple definition of `Connection::GetConnectedHostIdentifier()'
connection.o:Connection.cxx:(.text+0x5e): first defined here
connection.o: In function `Connection::NotifyAllObservers(char*, int)':
Connection.cxx:(.text+0x202): multiple definition of `Connection::NotifyAllObservers(char*, int)'
connection.o:Connection.cxx:(.text+0x202): first defined here
connection.o: In function `Connection::AttachObserver(ConnectionObserver*)':
Connection.cxx:(.text+0x322): multiple definition of `Connection::AttachObserver(ConnectionObserver*)'
connection.o:Connection.cxx:(.text+0x322): first defined here
connection.o: In function `Connection::~Connection()':
Connection.cxx:(.text+0x37c): multiple definition of `Connection::~Connection()'
connection.o:Connection.cxx:(.text+0x37c): first defined here
connection.o: In function `Connection::~Connection()':
Connection.cxx:(.text+0x490): multiple definition of `Connection::~Connection()'
connection.o:Connection.cxx:(.text+0x490): first defined here
connection.o: In function `Connection::~Connection()':
Connection.cxx:(.text+0x5a4): multiple definition of `Connection::~Connection()'
connection.o:Connection.cxx:(.text+0x5a4): first defined here
connection.o: In function `Connection::Connection(Port*, int)':
Connection.cxx:(.text+0x6b8): multiple definition of `Connection::Connection(Port*, int)'
connection.o:Connection.cxx:(.text+0x6b8): first defined here
connection.o: In function `Connection::Connection(Port*, int)':
Connection.cxx:(.text+0x7ee): multiple definition of `Connection::Connection(Port*, int)'
connection.o:Connection.cxx:(.text+0x7ee): first defined here
connection.o: In function `Connection::ReceiveThreadBody()':
Connection.cxx:(.text+0x924): multiple definition of `Connection::ReceiveThreadBody()'
connection.o:Connection.cxx:(.text+0x924): first defined here
semaphore.o: In function `Semaphore_ASM::post()':
Semaphore_ASM.cpp:(.text+0x11): undefined reference to `sem_post'
semaphore.o: In function `Semaphore_ASM::pend()':
Semaphore_ASM.cpp:(.text+0x47): undefined reference to `sem_wait'
semaphore.o: In function `Semaphore_ASM::~Semaphore_ASM()':
Semaphore_ASM.cpp:(.text+0x87): undefined reference to `sem_destroy'
semaphore.o: In function `Semaphore_ASM::~Semaphore_ASM()':
Semaphore_ASM.cpp:(.text+0xc3): undefined reference to `sem_destroy'
semaphore.o: In function `Semaphore_ASM::~Semaphore_ASM()':
Semaphore_ASM.cpp:(.text+0xff): undefined reference to `sem_destroy'
semaphore.o: In function `Semaphore_ASM::Semaphore_ASM(int)':
Semaphore_ASM.cpp:(.text+0x141): undefined reference to `sem_init'
semaphore.o: In function `Semaphore_ASM::Semaphore_ASM(int)':
Semaphore_ASM.cpp:(.text+0x16f): undefined reference to `sem_init'
thread_asm.o: In function `Thread_ASM::~Thread_ASM()':
Thread_ASM.cpp:(.text+0x12e): undefined reference to `pthread_kill'
Thread_ASM.cpp:(.text+0x142): undefined reference to `pthread_join'
thread_asm.o: In function `Thread_ASM::~Thread_ASM()':
Thread_ASM.cpp:(.text+0x1e4): undefined reference to `pthread_kill'
Thread_ASM.cpp:(.text+0x1f8): undefined reference to `pthread_join'
thread_asm.o: In function `Thread_ASM::~Thread_ASM()':
Thread_ASM.cpp:(.text+0x29a): undefined reference to `pthread_kill'
Thread_ASM.cpp:(.text+0x2ae): undefined reference to `pthread_join'
thread_asm.o: In function `Thread_ASM::Join()':
Thread_ASM.cpp:(.text+0x385): undefined reference to `pthread_join'
thread_asm.o: In function `Thread_ASM::Start(bool)':
Thread_ASM.cpp:(.text+0x3f9): undefined reference to `pthread_create'
thread_asm.o: In function `Thread_ASM::Thread_ASM(void* (*)(void*), void*, unsigned int, int, int, int, int)':
Thread_ASM.cpp:(.text+0x4bf): undefined reference to `pthread_attr_setstacksize'
thread_asm.o: In function `Thread_ASM::Thread_ASM(void* (*)(void*), void*, unsigned int, int, int, int, int)':
Thread_ASM.cpp:(.text+0x5f7): undefined reference to `pthread_attr_setstacksize'
So for some reason every single function in the Connection class has been defined multiple times. I assume because it's included as a dependency for multiple targets, but I've seen this in numerous examples that apparently work.
Everything in libpthread is undefined because I'm not linking in the library. I've tried adding the library options to the LDFLAGS variable but that doesn't seem to work either.
Can anyone give me pointers on where to go from here? Thanks much
This looks more like a broken header file. Do you have something like this at the top of "Connection.h":
Code:
#ifndef __CONNECTION_H
#define __CONNECTION_H
and a line like this at the bottom
Code:
#endif // __CONNECTION_H
That makes sure that the file is included once, and only once, no matter how many times the compiler sees
Code:
#include "Connection.h"
Also, you need to add "-lpthreads" to your LDFLAGS.
I do have the #ifndef/#define block in all my headers files, and I've tried the -lpthreads in LDFLAGS to no avail :\ I've also tried -lrt which is what I've used in other projects that use posix semaphores and mutexes but this has also not worked. I get this message:
Code:
g++: -lpthreads: linker input file unused because linking not done
g++: -lrt: linker input file unused because linking not done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.