Question

i hope its ok that i post another question but i think its important to understand my problem. So im working on the opensource project Sumo and try to add a class sending data via http in json format. So the Project compiled and build the exe fine before i started my work. Then i added these two files :

#ifndef connect_h
#define connect_h


#include <utils/common/SUMOTime.h>


namespace jsonc
{
    class connect
    {
    public:

        static void write(SUMOTime timestep);
    private:
        static std::wstring convert(const std::string& as);
    };
}
#endif

And my code :

#include "jsonconnect.h"

#include <cpprest/http_client.h>
#include <cpprest/json.h>
#pragma comment(lib, "cpprest120_2_0.lib")
#pragma comment(lib, "C:/xerces-c-3.1.1-x86-windows-vc-10.0/lib/xerces-c_3.lib")

using namespace web;
using namespace web::http;
using namespace web::http::client;

#include <microsim/MSEdge.h>
#include <microsim/MSLane.h>
#include <microsim/MSNet.h>
#include <microsim/MSVehicle.h>
#include <utils/options/OptionsCont.h>
#include <utils/geom/GeoConvHelper.h>
#include <Windows.h>

namespace jsonc
{
    void connect::write(SUMOTime timestep) 
    {
        const bool signals = OptionsCont::getOptions().getBool("fcd-output.signals");
        MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl();
        MSVehicleControl::constVehIt it = vc.loadedVehBegin();
        MSVehicleControl::constVehIt end = vc.loadedVehEnd();

        json::value vehicles;
        json::value timestamp;
        timestamp[L"timestamp"] = json::value::string(convert(time2string(timestep)));
        vehicles[0] = timestamp;
        for (; it != end; ++it) {
            const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
            if (veh->isOnRoad()) {
                Position pos = veh->getPosition();
                MSLane* lane = veh->getLane();
                GeoConvHelper::getFinal().cartesian2geo(pos);

                json::value vehicle;
                vehicle[L"id"] = json::value::string(convert(veh->getID()));
                vehicle[L"x"] = json::value::number(pos.x());
                vehicle[L"y"] = json::value::number(pos.y());
                vehicle[L"angle"] = json::value::number(veh->getAngle());
                vehicle[L"speed"] = json::value::number(veh->getSpeed());
                vehicle[L"pos"] = json::value::number(veh->getPositionOnLane());
                vehicle[L"slope"] = json::value::number(lane->getShape().slopeDegreeAtOffset(veh->getPositionOnLane()));
                vehicle[L"lane"] = json::value::string(convert(lane->getID()));
                vehicle[L"type"] = json::value::string(convert(veh->getVehicleType().getID()));

                vehicles[1] = vehicle;

                //of.setPrecision(GEO_OUTPUT_ACCURACY);


                if (signals) {
                    //of.writeAttr("signals", toString(veh->getSignals()));
                }
            }

            http_client client(L"http://localhost:5140/");

            client.request(methods::POST, L"", vehicles.to_string().c_str(),
                L"application/json").then([](http_response response)
            {
                std::wcout << response.status_code() << std::endl;

                if (response.status_code() == status_codes::OK)
                {
                    auto body = response.extract_string();  
                }
            });
        }

    }
    std::wstring convert(const std::string& as)
    {
        // deal with trivial case of empty string
        if (as.empty())    return std::wstring();

        // determine required length of new string
        size_t reqLength = ::MultiByteToWideChar(CP_UTF8, 0, as.c_str(), (int)as.length(), 0, 0);

        // construct new string of required length
        std::wstring ret(reqLength, L'\0');

        // convert old string to new string
        ::MultiByteToWideChar(CP_UTF8, 0, as.c_str(), (int)as.length(), &ret[0], (int)ret.length());

        // return new string ( compiler should optimize this away )
        return ret;
    }
}

So the project already used xerces before and like i said it worked fine. Now when i added the nuget package casablanca and tried to build it i got some LNK errors with the casblanca classes and xerces. Well i added the prag,a to the libs and these errors disappeared. Instead im now getting LNK errors again and even more in the same project and another project .. im wondering im new to c++ but now im completely lost because why is he having problems now with stuff he already built fine before adding that project?

So thats the errors now and now im really lost because theres even like std:basic_string LNK error...

29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: class pplx::task<class web::http::http_response> __thiscall web::http::client::http_client::request(class web::http::http_request,class pplx::cancellation_token)" (__imp_?request@http_client@client@http@web@@QAE?AV?$task@Vhttp_response@http@web@@@pplx@@Vhttp_request@34@Vcancellation_token@6@@Z)".
29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""__declspec(dllimport) class std::shared_ptr<struct pplx::scheduler_interface> __cdecl pplx::get_ambient_scheduler(void)" (__imp_?get_ambient_scheduler@pplx@@YA?AV?$shared_ptr@Uscheduler_interface@pplx@@@std@@XZ)".
29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""__declspec(dllimport) long __cdecl pplx::details::platform::GetCurrentThreadId(void)" (__imp_?GetCurrentThreadId@platform@details@pplx@@YAJXZ)".
29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: void __thiscall pplx::details::critical_section_impl::unlock(void)" (__imp_?unlock@critical_section_impl@details@pplx@@QAEXXZ)".
29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: void __thiscall pplx::details::critical_section_impl::lock(void)" (__imp_?lock@critical_section_impl@details@pplx@@QAEXXZ)".
29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: __thiscall pplx::details::critical_section_impl::~critical_section_impl(void)" (__imp_??1critical_section_impl@details@pplx@@QAE@XZ)".
29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: __thiscall pplx::details::critical_section_impl::critical_section_impl(void)" (__imp_??0critical_section_impl@details@pplx@@QAE@XZ)".
29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: unsigned int __thiscall pplx::details::event_impl::wait(unsigned int)" (__imp_?wait@event_impl@details@pplx@@QAEII@Z)".
29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: void __thiscall pplx::details::event_impl::set(void)" (__imp_?set@event_impl@details@pplx@@QAEXXZ)".
29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: __thiscall pplx::details::event_impl::~event_impl(void)" (__imp_??1event_impl@details@pplx@@QAE@XZ)".
29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: __thiscall pplx::details::event_impl::event_impl(void)" (__imp_??0event_impl@details@pplx@@QAE@XZ)".
29>z_libmicrosim_output.lib(jsonconnect.obj) : error LNK2001: Nicht aufgelöstes externes Symbol ""private: static class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl jsonc::connect::convert(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?convert@connect@jsonc@@CA?AV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z)".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__accept@12".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__listen@8".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__send@16".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__gethostbyname@4".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__closesocket@4".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "___WSAFDIsSet@8".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__socket@12".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__bind@12".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__recv@16".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__WSACleanup@0".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__setsockopt@20".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__htons@4".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__WSAGetLastError@0".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__select@20".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__htonl@4".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__inet_addr@4".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__WSAStartup@8".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__connect@12".
29>zz_foreign_tcpip.lib(socket.obj) : error LNK2001: Nicht aufgelöstes externes Symbol "__imp__ioctlsocket@12".

Im really lost here and any help would really be appreciated. From what ive read at the other topics about the error im not really getting it because everything is defined since the build worked before i added that project? is there like a circle or something?

Was it helpful?

Solution

You may have resolved this issue since it's so old, but this might help others. The issue could be due to an error in the project properties in Visual Studio 2012.

If you head to:

Project Properties > C/C++ > Preprocessor > Preprocessor Definitions

And add the flag:

_NO_ASYNCRTIMP;

This prevents the compiler from trying to find the C++ REST SDK functions from a DLL. It should resolve your pplx linking errors.

Some other points that are important to note:

  • ensure that you are using the v110 binaries for your project, as those are intended for Visual Studio 2012
  • You may run across some ill-advised suggestions around the internet to "disable wchar_t" as a native type. This is generally a bad idea, because wchar_t IS a native type and the C++ REST SDK depends on it.
  • If the v110 binaries from the C++ REST SDK aren't linking properly, try the Windows XP version (v110_xp)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top