Jump to content
  • Advertisement
Sign in to follow this  

ZThread - Undefined references? err why?

This topic is 5038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

from zthread.sourceforge.net btw. I included teh include directory in my devc++ compiler options, but it keeps giving me undefined references:
#include <iostream>
#include <zthread/Runnable.h>
#include <zthread/Thread.h>

class LiftOff : public ZThread::Runnable
    LiftOff(int count, int id = 0)
    	: m_count(count), m_id(id) {}
   		{ std::cout << m_id << " completed.\n"; }

    void run()
        while (m_count--)
        	std::cout << m_id << " : " << m_count << std::endl;
       	std::cout << "LiftOff!!!\n";
    int m_count, m_id;

int main()
    	ZThread::Thread thrd(new LiftOff(10, 12));
    	std::cout << "Waiting for Lift Off";
    catch (ZThread::Synchronization_Exception &e)
        std::cout << e.what();
    return 0;

Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\ZThreads\Makefile.win"
Executing  make clean
rm -f LiftOffThread01.o  ZThread.exe

g++.exe -c LiftOffThread01.cpp -o LiftOffThread01.o -I"C:/DEV-CPP/include/c++/3.3.1"  -I"C:/DEV-CPP/include/c++/3.3.1/mingw32"  -I"C:/DEV-CPP/include/c++/3.3.1/backward"  -I"C:/DEV-CPP/lib/gcc-lib/mingw32/3.3.1/include"  -I"C:/DEV-CPP/include"  -I"C:/boost/boost_1_31_0"  -I"C:/fmod/fmodapi374win/api/inc"  -I"C:/ZThread-2.3.1/include"   

g++.exe LiftOffThread01.o  -o "ZThread.exe" -L"C:/DEV-CPP/lib"  

LiftOffThread01.o(.text+0xd1):LiftOffThread01.cpp: undefined reference to `ZThread::Thread::Thread(ZThread::Task const&, bool)'
LiftOffThread01.o(.text+0x1a0):LiftOffThread01.cpp: undefined reference to `ZThread::Thread::~Thread()'
LiftOffThread01.o(.text+0x1c9):LiftOffThread01.cpp: undefined reference to `ZThread::Thread::~Thread()'
LiftOffThread01.o(.text$_ZN7ZThread10CountedPtrINS_8RunnableENS_11AtomicCountEED2Ev+0x17):LiftOffThread01.cpp: undefined reference to `ZThread::AtomicCount::operator--()'
LiftOffThread01.o(.text$_ZN7ZThread10CountedPtrINS_8RunnableENS_11AtomicCountEED2Ev+0x5e):LiftOffThread01.cpp: undefined reference to `ZThread::AtomicCount::~AtomicCount()'
LiftOffThread01.o(.text$_ZN7ZThread10CountedPtrINS_8RunnableENS_11AtomicCountEEC2I7LiftOffEEPT_+0x63):LiftOffThread01.cpp: undefined reference to `ZThread::AtomicCount::AtomicCount()'
LiftOffThread01.o(.text$_ZN7ZThread10CountedPtrINS_8RunnableENS_11AtomicCountEEC2I7LiftOffEEPT_+0xca):LiftOffThread01.cpp: undefined reference to `ZThread::AtomicCount::operator++(int)'

Execution terminated

Share this post

Link to post
Share on other sites
The linker line:
g++.exe LiftOffThread01.o -o "ZThread.exe" -L"C:/DEV-CPP/lib"
doesn't contain any reference to the ZThread library.

In the parameters tab of the project options window add the ZThread library file and you app should compile. You might have to add its directory in the directories tab.

I don't know zthread but you might have to build the library from source if it isn't provided. If so instructions should have come with it, probably in a file called INSTALL.

Share this post

Link to post
Share on other sites
I tried findingthe .lib or .a file, but there was none, so I figured it would be just like the other libraries that I just include the headers.
SO I did, nad it worked just fine with only Runnable.h, and then I added Thread.h and everything got screwed.

Share this post

Link to post
Share on other sites
I downloaded the lib and checked it out. You are going to have to compile the lib from source (the src dirctory). There are minimal instructions in the BUILDING and INSTALL files.

EDIT: You could use the Runnable class without the lib because its a pure virtual interface class. All it does is provide a function to be overrided and an empty virtual destructor.

Share this post

Link to post
Share on other sites
I'm a little bit (really) confused.
Does that mean that if Im running windows, I have to add the 3 .cxx files in the src/win32 and compile them separetely?

Share this post

Link to post
Share on other sites
You have to configure the makefile and then when you compile the right files and settings will be used. And I agree that its confusing, there might be tutorials on the net about getting ZThread up and running.

Share this post

Link to post
Share on other sites
This really is confusing, I tried googling for a detailed explanation, but I still can't seem to get one. I just don't know where I'm supposed to type ./configure && make install

I got instructions for it from Thinking in Cpp, but they seem too vague for me (maybe because I don't know what the hell he is talking about 30% of the time).

Installing ZThreads

Please note that the ZThread library is an independent project and is not supported by the authors of this book; we are simply using the library in this chapter and cannot provide technical support for installation issues. See the ZThread web site for installation support and error reports.

The ZThread library is distributed as source code. After downloading it (version 2.3 or greater) from the ZThread web site, you must first compile the library, and then configure your project to use the library.

The preferred method for compiling ZThreads for most flavors of UNIX (Linux, SunOS, Cygwin, etc.) is to use the configure script. After unpacking the files (using tar), simply execute:
./configure && make install

from the main directory of the ZThreads archive to compile and install a copy of the library in the /usr/local directory. You can customize a number of options when using this script, including the locations of files. For details, use this command:
./configure –help

The ZThreads code is structured to simplify compilation for other platforms and compilers (such as Borland, Microsoft, and Metrowerks). To do this, create a new project and add all the .cxx files in the src directory of the ZThreads archive to the list of files to be compiled. Also, be sure to include the include directory of the archive in the header search path for your project. The exact details will vary from compiler to compiler so you’ll need to be somewhat familiar with your toolset to be able to use this option.

Once the compilation has succeeded, the next step is to create a project that uses the newly compiled library. First, let the compiler know where the headers are located so that your #include statements will work properly. Typically, you will add an option such as the following to your project:

If you used the configure script, the installation path will be whatever you selected for the prefix (which defaults to /usr/local). If you used one of the project files in the build directory, the installation path would simply be the path to the main directory of the ZThreads archive.

Next, you’ll need to add an option to your project that will let the linker know where to find the library. If you used the configure script, this will look like:
-L/path/to/installation/lib –lZThread

If you used one of the project files provided, this will look like:
-L/path/to/installation/Debug ZThread.lib

Again, if you used the configure script, the installation path will be whatever you selected for the prefix. If you used a provided project file, the path will be the path to the main directory of the ZThreads archive.

Note that if you’re using Linux, or if you are using Cygwin (www.cygwin.com) under Windows, you may not need to modify your include or library path; the installation process and defaults will often take care of everything for you.

Under Linux, you will probably need to add the following to your .bashrc so that the runtime system can find the shared library file LibZThread-x.x.so.O when it executes the programs in this chapter:

export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}

(Assuming you used the default installation process and the shared library ended up in /user/local/lib; otherwise, change the path to your location).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!