2019 error

Hi, I'm new here, I'm working for a game and I can't understand this error:


LNK2019 external reference "void __cdecl SPRITE(void)" (?SPRITE@@YAXXZ) _SDL_main

Something like this..

I can't copy the full source code because it's too long, if you need other informations about the code then tell me what you need please.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//entity.h
#pragma once
#include <SDL.h>
#include <vector>

class Entity
{
public:
    int Life = 200;
    SDL_Texture *image;
    ....
}
void SPRITE(void);

//entity.cpp
#pragma once
#include "stdafx.h"
#include <iostream>
#include <SDL.h>
#include <time.h>
#include <cstdlib>
#include <thread>
#include <vector>
#include <SDL_image.h>
#include "main.h"
#include "entity.h"

using namespace std;

Entity First() {
	Entity obj;
	extern SDL_Renderer *renderer;
	extern const int codeStill, codeAttack;
        //operations on the object..
        return obj;

void SPRITE(void)
{
    extern bool done;
    extern Entity Character;
    extern const int codeStill, codeAttack;
    Character.action = codeStill; //just an example, it is very similiar to what it does in the 
source code.
}

//main.cpp
#include "entity.h"
Entity base;
Entity All_Entities[5] = {base,base,base,base,base}; //could change in 'SPRITE' function
int main(int argc, char *argv[])
{
    srand(time(NULL));

    extern SDL_Window *window;
    extern SDL_Renderer *renderer;
    extern SDL_Rect camera; 
    extern SDL_Texture* wallpaper;
    extern SDL_Texture* back_wallpaper;
    extern Entity All_Entities[20];
    SDL_Init(SDL_INIT_EVERYTHING);
    IMG_Init(IMG_INIT_PNG| IMG_INIT_JPG);

    ....

    std::thread Sprites(SPRITE);
    
    //main loop
    return 0;
}

//Platform.h
#pragma once
#include <iostream>
//The class rapresenting a platform
class Platform {
public:
	SDL_Rect pos;
	SDL_Texture *image;
	bool through = true;

	Platform(SDL_Rect pos, SDL_Texture *image)
		:pos(pos), image(image)
	{}
};

I think it's all, if you have some idea about what can cause the problem (like if I use threading then threads are using the same variables, exc..) then tell me what do you think and i will answer.
Last edited on
std::thread Sprites(SPRITE);

This appears to be a declaration that a function exists, named Sprites, that takes an object of type SPRITE and return a std::thread. Is that what you meant?
No, I'm not very expert in threads.. but
std::thread Sprites(SPRITE);
could start the thread, named 'Sprites', that runs the 'SPRITE' function, doesn't it?
Oh right. Anyway, the complaint from the linker is that it can't find anywhere the function void SPRITE(void). Which suggests that however you're building this, it doesn't have entity.cpp in it
Sorry but... then, where is the problem? What i need to change?
Your class doesn't have a semicolon to finish it, and that could give very weird errors.
Oh, i think semicolons are only in the original source code, maybe it's just a transcription error. Tomorrow i will check.
Ok, yes, i forgot to copy semicolons, in the source code there are.
What is defined in main.h? Anything important? Seems odd that entity.cpp includes main.h, and main.cpp includes entity.h. How are you building (Visual Studio, CodeBlocks , command-line, etc?) Are the extern references within SPRITE defined at some point?

You said that your code is too long to post. I agree, it probably is. But what you should do is whittle down your code (In a COPIED project/directory) until it only has the absolute essentials needed to reproduce the same error. What should be left is only a few lines in each file.
Last edited on
You should try to compile your code using the command line, or just simplify your code to a really small example pinpointing the root cause of your error (always do that before posting on a forum so you can post full code, and in many cases people solve the problem by doing this).

If you understood how the command line worked, you could read the compiler logs to figure out if your IDE project is screwing something up with linking. Other than that you could post your logs to us. You should've taken the hint from repeater that entity.cpp is not "existing", so if he is right, you could move the contents of entity.cpp to main.cpp and it will work (implying that main.cpp "exists").
Ok, then...
Actually in "main.h" there are only some values as the size of the window exc., nothing important, maybe a "using namespace std;": every files use it.

I'm using Visual Studio.

In entity.h there is also a function that returns an Entity object.

I will try to edit the post writing something else. However, thank you for the help!
Hey, what do you need/think?
I'm still waiting and I can't continue without solve the problem.
Just do what my or Ganado's post said, and tell us your results.

Also we already know you are using the visual studios compiler because you posted LNK2019, Ganado was asking how you did it (he mentioned codeblocks since it could technically use visual studios compiler I guess), and the best way to do this is to post your compile logs.
Topic archived. No new replies allowed.