freeGLUT framework.cpp structure question

I have been studying the “Learning Modern 3D Graphics Programming” online book by Jason L. Mckesson and was hoping there were people still around that know of the book and would be able to help me.
I have reached a point of confusion right at the beginning of chapter 1 it says “The framework file expects 5 functions to be defined: defaults , init , display , reshape , and keyboard.”
My question is the following: How does the framework.cpp file know to look for the 5 functions in the tut1.cpp file?

Is there a link of some sort? Some sort of drop down menu in Visual Studio that says “We want to use those specific functions with those names in tut1.cpp”?

As you quoted framework.cpp expects those five functions to be defined in another translation unit - that expectation is expressed by declaring (but not defining) the functions (see here) and then registering (some of) those functions as callbacks with glut (here).

I don’t know what a “translation unit” is. from my searching, I surmise that you mean “another cpp file” when you say “another translation unit.”
I understand that it declares void init() in framework.cpp, (I mean it only half makes sense to me, because I have no idea how VS knows that you are JUST declaring a function not declaring and defining at the same time like is normally done in tutorials)
but that still doesn’t show where the link is made. I am looking for some setting, code or otherwise that says "Hey, when I declare “void initi()” I am talking about the the “void init()” from tut1.cpp.
Or is the answer that glut is a black box middle man that takes in “void initi()” and says “I got this, I know you mean “void initi()” from tut1.cpp”

Also, you said that framework.cpp expects those five functions to be defined in another translation. The two links you provided link to the same translation unit: framework.cpp. What are the other translation units you are referring to?

It’s the difference between this:

void function();

And this:

void function()
{
// implementation.
}

It’s made in the linker.

There isn’t one. There doesn’t need to be. The object files built from each translation unit know what they provide and what they require. When you link them all together, the linker goes through and fills in the requirements from what other object files provide. If no object files provide something one object file requires, then you get a linker error.

That’s what my theory was as well. So I decided to create two test projects, completely separate from the tutorial. And that doesn’t work.
I created project A with A.cpp

#include <iostream>
#include <string>
void B();
int main()
{
	B();
	return 0;
}

and project B with B.cpp

#include <iostream>
#include <string>

void B()
{
	std::cout << "Hello, World";
}

When I run it, it throws two errors:
LNK2019 unresolved external symbol _main referenced in function int __cdecl invoke_main(void) (?invoke_main@@YAHXZ)
LNK1120 1 unresolved externals

Obviously something is missing. and I suspect that the linker is the culprit. I probably need to select some sort of drop down or file directory.

Alfonse_Reinheart
There isn’t one. There doesn’t need to be. The object files built from each translation unit know what they provide and what they require. When you link them all together, the linker goes through and fills in the requirements from what other object files provide. If no object files provide something one object file requires, then you get a linker error.

Yes there is. It is called the Linker. You said it yourself right above it. You go to project Properties > Linker > Input > Additional Dependencies then enter the directory for the other files library. THAT is how you tell VS “Hey, when I am declaring these functions, I want to use the functions from this library when I do it”

Problem solved. Thanks guys, you both helped set me down the right path. :smiley:

But that’s not what that setting says. It does not specifically say that symbol X comes from file Y. You’re specifying a list of library files, any one of which could provide any symbols requested by any of the object files, both in your project and in other libraries that your project includes.

That’s true, but it accomplishes that effect by saying “If you are looking for a specific function, you should also be looking in here”
I wish I could have been more precise with my question. Now knowing the solution, I would have worded my question like this:
How does the the framework file know where to look to find a function that is in a separate file?
The answer would have been:
Use the Linker to make the file containing the function available to the framework file.