O
O
obozeetogribochki2021-06-22 00:43:09
C++ / C#
obozeetogribochki, 2021-06-22 00:43:09

Link to an unresolved external symbol, what is it and how to fix it?

I made a menu for the game according to the guide on YouTube, but I had a problem in the form of these errors:

Here is the menu code
#include <SFML/Graphics.hpp>
using namespace sf;

void menu(RenderWindow& window) {

  

  Texture menuTexture1, menuTexture2, menuTexture3, aboutTexture, menuBackground;
  menuTexture1.loadFromFile("images/111.png");
  menuTexture2.loadFromFile("images/222.png");
  menuTexture3.loadFromFile("images/333.png");
  aboutTexture.loadFromFile("images/about.png");
  menuBackground.loadFromFile("images/Penguins.jpg");
  Sprite menu1(menuTexture1), menu2(menuTexture2), menu3(menuTexture3), about(aboutTexture), menuBg(menuBackground);
  bool isMenu = 1;
  int menuNum = 0;
  menu1.setPosition(100, 30);
  menu2.setPosition(100, 90);
  menu3.setPosition(100, 150);
  menuBg.setPosition(345, 0);

  //////////////////////////////МЕНЮ///////////////////
  while (isMenu)
  {
    menu1.setColor(Color::White);
    menu2.setColor(Color::White);
    menu3.setColor(Color::White);
    menuNum = 0;
    window.clear(Color(129, 181, 221));

    if (IntRect(100, 30, 300, 50).contains(Mouse::getPosition(window))) { menu1.setColor(Color::Blue); menuNum = 1; }
    if (IntRect(100, 90, 300, 50).contains(Mouse::getPosition(window))) { menu2.setColor(Color::Blue); menuNum = 2; }
    if (IntRect(100, 150, 300, 50).contains(Mouse::getPosition(window))) { menu3.setColor(Color::Blue); menuNum = 3; }

    if (Mouse::isButtonPressed(Mouse::Left))
    {
      if (menuNum == 1) isMenu = false;//если нажали первую кнопку, то выходим из меню 
      if (menuNum == 2) { window.draw(about); window.display(); while (!Keyboard::isKeyPressed(Keyboard::Escape)); }
      if (menuNum == 3) { window.close(); isMenu = false; }

    }

    window.draw(menuBg);
    window.draw(menu1);
    window.draw(menu2);
    window.draw(menu3);

    window.display();
  }
  ////////////////////////////////////////////////////
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2021-06-22
@Nipheris

I think you have created a console application instead of a window one. You can recreate the project and select Win32 Application as a template and place your code in it (I recommend this option), or try changing the subsystem from Console to Windows in the linker settings (most likely, you will also need to manually set the entry point.).

A
Alexey Bereznikov, 2021-06-22
@gdt

So what kind of error is the problem? You attached the menu code itself as errors :) Have a
look at SFML and Visual Studio , do you have your project set up correctly? In particular, pay attention to Configuration Properties/Linker/Input/Additional Dependencies, you should have either SFML listed there. As an option, instead, in VS you can write like this:

#pragma comment(lib, "sfml-graphics.lib")
#pragma comment(lib, "sfml-window.lib")
#pragma comment(lib, "sfml-system.lib")

Add this code between #include and main, try again.
A reference to an unresolved external symbol means that you are using some entity somewhere in the code for which there is a description (usually in the header file, otherwise nothing would have been compiled for you), and the linker, in turn, cannot find where the entity itself (class/function for example) with such a description. These entities in your case are defined in lib files, and they must be passed to the linker immediately after compilation so that it can assemble a working program from the pieces that it has (your_program.obj, lib files from SFML, crt, and so on ).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question