-1

My code for Text_Box.cpp is:

#include <SFML/Graphics.hpp>

int main1() {
    sf::RenderWindow window(sf::VideoMode(800, 600), "Window",
        sf::Style::Titlebar | sf::Style::Close);
    sf::Font arial;
    arial.loadFromFile("arial.ttf");
    sf::Text t;
    t.setFillColor(sf::Color::White);
    t.setFont(arial);
    std::string s = "This is text that you type: ";
    t.setString(s);

    while (window.isOpen()) {
        sf::Event event;

        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
            if (event.type == sf::Event::TextEntered) {
                if (event.text.unicode < 128) {
                    s += static_cast<char>(event.text.unicode);
                }
                else {
                    // Time to consider sf::String or some other unicode-capable string
                }
            }
        }
        t.setString(s);
        window.clear(sf::Color::Black);
        window.draw(t);
        window.display();
    }
    return 0;
}

I copied this above code to learn by changing commands from it. I am including it in my main file of c that is, main.c and using it at the very beginning of main function. My main.c code is:

#include <stdio.h>
#include "Text_Box.cpp"

int main() {
    main1();
    return 0;
}

but it is giving several errors like:

Severity    Code    Description Project File    Line    Suppression State
Error   C4233   nonstandard extension used: '__is_final' keyword only supported in C++, not C   Project1    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits 543 

Severity    Code    Description Project File    Line    Suppression State
Error   C4233   nonstandard extension used: '__is_trivially_constructible' keyword only supported in C++, not C Project1    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\type_traits 741 

etc. I am using visual studio 2019. How can it be fixed? Is there something I am doing wrong? I have a doubt that do I need to compile SFML on my own as I am using visual studio 2019?

EDIT: I tried without main.c file, renaming main1 to main and after adding additional dependencies, it is giving errors on executing: sfml-graphic-d-2.dll not found, sfml-window-d-2.dll not found, sfml-system-d-2.dll not found. It also says reinstalling may fix this. So do I need to compile sfml as website of sfml mentions this?

Himanshu
  • 21
  • 6
  • Never `#include` cpp files, you should create a header file instead. You'll have to make sure that header is compatible with both c and c++ – Alan Birtles Sep 11 '22 at 07:32
  • At a guess your 64-bit project settings are missing the include directories you've specified in the 32-bit one – Alan Birtles Sep 11 '22 at 09:03
  • @AlanBirtles I applied the same configuration settings to x64 and it gives the same error of x86 now. – Himanshu Sep 11 '22 at 09:04
  • see https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix you are presumably not linking to all the libraries you need to or the libraries aren't compatible with your compiler – Alan Birtles Sep 11 '22 at 09:07
  • @AlanBirtles After adding additional dependencies mentioned under sfml-graphics, it compiled but it says ```sfml-graphic-d-2.dll```,```sfml-windows-d-2.dll```,```sfml-system-d-2.dll``` not found. – Himanshu Sep 11 '22 at 09:30
  • You need to make sure the dlls are on your path or copied to the executable directory – Alan Birtles Sep 11 '22 at 09:52
  • @AlanBirtles Thank you. Sorry for being late in saying this. – Himanshu Sep 11 '22 at 12:19

1 Answers1

0

The compiler needs to specify (in the project settings)

/Zc:__cplusplus

Never do it bellow. Remove main.c and rename main1 to main.

main.c

#include <stdio.h>
#include "Text_Box.cpp"

int main() {
    main1();
    return 0;
}
273K
  • 29,503
  • 10
  • 41
  • 64