reo7sp / tgbot-cpp

C++ library for Telegram bot API
http://reo7sp.github.io/tgbot-cpp
MIT License
1.02k stars 247 forks source link

Error LNK2001: unresolved external symbol #319

Open Amirhan-Taipovjan-Greatest-I opened 1 month ago

Amirhan-Taipovjan-Greatest-I commented 1 month ago

Hello! I'm currently experiencing some Issues with InlineQuery...

My Code:

        bot.getEvents().onInlineQuery([&bot](const InlineQuery::Ptr& query) {

            std::vector<InlineQueryResult::Ptr> results;
            InlineQueryResultArticle::Ptr article(new InlineQueryResultArticle);

            auto text = InputTextMessageContent();
            text.messageText = "Inline Test";

            article->title = "Inline Title!";
            article->id = "1234";
            article->type = "article";
            results.push_back(article);

            bot.getApi().answerInlineQuery(query->id, results);
            });

Errors in Visual Studio:

1>main.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const TgBot::InlineQueryResultArticle::TYPE" (?TYPE@InlineQueryResultArticle@TgBot@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B).
1>main.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const TgBot::InputTextMessageContent::TYPE" (?TYPE@InputTextMessageContent@TgBot@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B).

I don't actually know if My Issue is about My code, to be honest... I tried do anything to fix that, but Issue still persists. Used tgbot-cpp Version (via vcpkg): 1.7.3.

Amirhan-Taipovjan-Greatest-I commented 1 month ago

Even this Code:

        bot.getEvents().onInlineQuery([&bot](const InlineQuery::Ptr& query) {
            vector<InlineQueryResult::Ptr> lol;
            InlineQueryResultArticle::Ptr rofl(new InlineQueryResultArticle);

            auto testus = InputTextMessageContent();
            testus.messageText = "lol";

            rofl->title = "Inline Title!";
            rofl->id = "1234";
            lol.push_back(rofl);

            bot.getApi().answerInlineQuery(query->id, lol);
        });

And even reinstalling tgbot-cpp via vcpkg didn't help, the Issue still persists!

Amirhan-Taipovjan-Greatest-I commented 1 month ago

Temporary fix for this Issue is:

Putting this Piece of Code in your .cpp:

using namespace std;
using namespace TgBot;

const string InlineQueryResultCachedAudio::TYPE = "audio";
const string InlineQueryResultCachedDocument::TYPE = "document";
const string InlineQueryResultCachedGif::TYPE = "gif";
const string InlineQueryResultCachedMpeg4Gif::TYPE = "mpeg4_gif";
const string InlineQueryResultCachedPhoto::TYPE = "photo";
const string InlineQueryResultCachedSticker::TYPE = "sticker";
const string InlineQueryResultCachedVideo::TYPE = "video";
const string InlineQueryResultCachedVoice::TYPE = "voice";

const string InlineQueryResultArticle::TYPE = "article";
const string InlineQueryResultAudio::TYPE = "audio";
const string InlineQueryResultContact::TYPE = "contact";
const string InlineQueryResultGame::TYPE = "game";
const string InlineQueryResultDocument::TYPE = "document";
const string InlineQueryResultGif::TYPE = "gif";
const string InlineQueryResultLocation::TYPE = "location";
const string InlineQueryResultMpeg4Gif::TYPE = "mpeg4_gif";
const string InlineQueryResultPhoto::TYPE = "photo";
const string InlineQueryResultVenue::TYPE = "venue";
const string InlineQueryResultVideo::TYPE = "video";
const string InlineQueryResultVoice::TYPE = "voice";
const string InputTextMessageContent::TYPE = "text";
const string InputLocationMessageContent::TYPE = "location";
const string InputVenueMessageContent::TYPE = "venue";
const string InputContactMessageContent::TYPE = "contact";
const string InputInvoiceMessageContent::TYPE = "invoice";
Amirhan-Taipovjan-Greatest-I commented 1 month ago

Couldn't solve some more Errors and decided to use #113 Code Piece... yep, it worked as intended, with My Addendum.