boost library problem

Started by
9 comments, last by Devil0150 14 years, 5 months ago
I installed boost library for c++, I built it and stuff. I tried the example code that was at the boost website and it worked. But I dont know how to work with Boost.thread library. I built it with bjam, and I tried some code that came with the installation, but I get some errors. I think I have to do something with the linker, but I dont know what. Im using Visual C++ 2008. Code:

// Copyright (C) 2001-2003
// William E. Kempf
//
//  Distributed under the Boost Software License, Version 1.0. (See accompanying 
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <boost/thread/thread.hpp>
#include <iostream>

void helloworld()
{
    std::cout << "Hello World!" << std::endl;
}

int main()
{
    boost::thread thrd(&helloworld);
    thrd.join();
}

Errors from the Build Log:

Output Window      
Linking...
asd.obj : error LNK2001: unresolved external symbol __imp__key
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
C:\Documents and Settings\User\My Documents\Visual Studio 2008\Projects\test\Debug\test.exe : fatal error LNK1120: 2 unresolved externals

Advertisement
main should be
int main(int argc, char ** argv)
if your compiling with multibyte character set, use wchar_t if your compiling with unicode character set.
GBS
I'm sorry but I accidentally built another code and not the one I wrote. The code I wrote earlier works fine. But this one doesn't:
#include <boost/thread/thread.hpp>#include <allegro.h>#include <iostream>void test(){}int main(int argc, char * argv){	std::cout << "Waiting for thread to begin.\n";	while (!key[KEY_1_PAD])	{		system("pause");	}	boost::thread myThread(&test);	myThread.join();	system("pause");	return 0;}END_OF_MAIN()


The errors are same as before but the first one. I fixed it. I had forgot to include the allegro library files in the linker.
I tried replacing main with what GraphicsBas said, but it didnt work.
Did you create a console project or a windows application? If your are building a windows application your entry point is the WinMain method.

You can check it out under the linker->system options.
GBS
No, its a Console application. This is what I got at linker -> system

Console (/SUBSYSTEM:CONSOLE)
Are you building for unicode? It in the general option pane of your project. If so you should use the
int main(int argc, wchar_t **argv)
signature instead or change the character set to multibyte.

Also what is the END_OF_MAIN() macro and the end of the file?
GBS
I am using unicode and I tried the wchar_t instead of char but I still get the errors.

END_OF_MAIN() is a required macro of allegro library.
The signature of your main is int main(int argc, char * argv). It should be char* argv[] or char** argv, depending on personal taste.
I tried that. Still the same errors.
Quote:Original post by Devil0150
No, its a Console application. This is what I got at linker -> system

Console (/SUBSYSTEM:CONSOLE)


In that case, add #define ALLEGRO_USE_CONSOLE before including allegro; if you weren't using the console then you'd change the subsystem to a WIN32 application.

This topic is closed to new replies.

Advertisement