0

Simply try to build code copied and pasted from a Boost tutorial. (see below)

I have the header only file, no built libraries as of yet.

Problem is I am getting two errors:

Error 1 error LNK1104: cannot open file 'libboost_system-vc100-mt-gd-1_53.lib' \\selafap01\homedrives\mgibson\My Documents\Visual Studio 2010\Projects\C++ Boost Test\C++ Boost Test\LINK C++ Boost Test

2 IntelliSense: #error directive: "Incompatible build options" c:\boost\config\auto_link.hpp 111 4

Regardless of what I do it seems to want a .lib file, which I don't really know how to do.

#include <boost/asio.hpp>

class SimpleSerial
{
public:
/**
 * Constructor.
 * \param port device name, example "/dev/ttyUSB0" or "COM4"
 * \param baud_rate communication speed, example 9600 or 115200
 * \throws boost::system::system_error if cannot open the
 * serial device
 */
SimpleSerial(std::string port, unsigned int baud_rate)
: io(), serial(io,port)
{
    serial.set_option(boost::asio::serial_port_base::baud_rate(baud_rate));
}

/**
 * Write a string to the serial device.
 * \param s string to write
 * \throws boost::system::system_error on failure
 */
void writeString(std::string s)
{
    boost::asio::write(serial,boost::asio::buffer(s.c_str(),s.size()));
}

/**
 * Blocks until a line is received from the serial device.
 * Eventual '\n' or '\r\n' characters at the end of the string are removed.
 * \return a string containing the received line
 * \throws boost::system::system_error on failure
 */
std::string readLine()
{
    //Reading data char by char, code is optimized for simplicity, not speed
    using namespace boost;
    char c;
    std::string result;
    for(;;)
    {
        asio::read(serial,asio::buffer(&c,1));
        switch(c)
        {
            case '\r':
                break;
            case '\n':
                return result;
            default:
                result+=c;
        }
    }
}

private:
    boost::asio::io_service io;
    boost::asio::serial_port serial;
};

Any direction on how to get that lib file as it really doesn't seem to be in the Boost header only directory anywhere, computer search doesn't find anything either.. would be very appreciated.

Cheers

EDIT 1:

Was able to generate the .lib file that was neccessary but navigating the boost directory in Visual Studio command prompt and running bootstrap.bat, this generate b2.exe, I ran that and the stage/lib directory was generated with the needed binaries.

However, now I am getting another error.. "error LNK1561: entry point must be defined"

I guess the circle of errors goes on :)

EDIT 2: The entry point being referred to was main(). Forgot the main! Oh well, added in a main and all is well!

mgibson
  • 6,103
  • 4
  • 34
  • 49

3 Answers3

3

For the first error: rightclick on the project in VStudio -> Properties -> Linker ->General -> Additional Library Directories "boost\stage\lib" it seems that you tried to link the wrong folder. Also check that the file

libboost_system-vc100-mt-gd-1_53.lib

is in the boost\stage\lib folder.

Captain GouLash
  • 1,257
  • 3
  • 20
  • 33
  • Ok initially I didn't have that, I had to run bootstrap.bat that came with the boost files to generate that file. Now I have that .lib file and the error has gone as I linked in that way - cheers. However, now I have a different error... "error LNK1561: entry point must be defined".. any ideas? – mgibson Mar 20 '13 at 11:15
  • after you run bootstrap.bat run this command : ( b2 --toolset=msvc-10.0 --build-type=complete stage ) if you use visual studio 2010. otherwise use msvc-11.0 for visual studio 2012. Also you can add to the command -j4 to speed this process up. (4 if you have a quadcore, 2 if you have a dualcore...) – Captain GouLash Mar 20 '13 at 11:17
  • So I ran that command, it said updated 2268 targets and the command prompt resumed its standard state. However the same error is still occuring – mgibson Mar 20 '13 at 12:21
  • to ensure its not the simplest error it could be : do you have a main function? – Captain GouLash Mar 20 '13 at 12:25
  • Ahh hold the phone, it is indeed working now. I was missing a main function.. Doh! I appreciate the help though, that command after bootstrap was still needed. Thanks – mgibson Mar 20 '13 at 12:31
0

You will need to install boost and have the libraries present if you're doing a static link in your build. Once installed, you will be able to find and specify the path to the libraries as part of your VS project configuration.

Zaphod
  • 1,927
  • 11
  • 13
0

In my case Release mode runs well, but Debug mode show this error...

Try this: Right click on the project in VStudio Properties -> C/C++ -> Code General -> Runtime Library : change /MT to /MTD.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
KayWang
  • 71
  • 6