Help with compiler linkin #4328

Closed
opened 2021-07-16 13:52:49 +00:00 by pp9999 · 2 comments
pp9999 commented 2021-07-16 13:52:49 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:
Version: 1.83
Branch: docking

Back-end/Renderer/Compiler/OS
Windows 10
Microsoft Visual Studio Community 2019
Windows SDK: 10.0.18362.0
Platform toolset: v142
C++ standard: C++17
C: C17

My Issue/Question:
I was using it before to display debug info with dx9 window overlaying game window. Now I decided to go fancy and use newer docking version.
But it doesn't seem to be linking properly. It looks like newer stuff isn't linked. I can click stuff and it takes me right to the imgui.cpp to the proper function. But compiler says not found.
compl

Version/Branch of Dear ImGui: Version: 1.83 Branch: docking Back-end/Renderer/Compiler/OS Windows 10 Microsoft Visual Studio Community 2019 Windows SDK: 10.0.18362.0 Platform toolset: v142 C++ standard: C++17 C: C17 My Issue/Question: I was using it before to display debug info with dx9 window overlaying game window. Now I decided to go fancy and use newer docking version. But it doesn't seem to be linking properly. It looks like newer stuff isn't linked. I can click stuff and it takes me right to the imgui.cpp to the proper function. But compiler says not found. ![compl](https://user-images.githubusercontent.com/38459022/125958520-1e03cf65-c401-4120-a08e-803c4595fd20.png)
AidanSun05 commented 2021-07-16 15:37:17 +00:00 (Migrated from github.com)

TL;DR: Possible fixes are at the bottom of this comment.

In your case, you're getting a lot of LNK2001 errors. This is the linker telling you, "You've used this function, but I can't find its definition".

I'm going to clear up a misconception here:

it takes me right to the imgui.cpp to the proper function

That's a header file in your screenshot, not a source file as you thought.

A header file, which has the extension .h or (less commonly) .hpp, contains the function name, return type, and parameters. This is known as its signature. After the signature, there's just a semicolon. This is what we're seeing in your screenshot.

A source file, which has the extension .cpp, reiterates the function signature, but it also adds the function body, enclosed in { and }. This is the function's definition.

For example, take this sample header file:

// myheader.h

int myFunction();

What would you say if I were to ask you, "What would happen if we were to call int x = myFunction();? What would x be?"

Of course, you wouldn't be able to answer properly because you don't know what's inside of the function, you only know that it exists and returns some unspecified int. By defining it in another source file, it becomes clear what the function does:

// mysource.cpp

int myFunction() {
    std::cout << "Hello\n";
    return 4;
}

This is what's happening when you get LNK2001 or LNK2019. In your screenshot, we're asking MSVC "What would happen if we called ImGui::EndColumns()?" but we didn't provide the source file that it's defined in; we only provided the header file shown in your screenshot. This causes the linker to fail.

There are several possible fixes to this issue:

  1. Make sure you've updated all your files. You may be trying to compile an old file that doesn't have the needed function definition.
  2. Check that all your files are being included during compile. You can go into your Solution Explorer in Visual Studio and make sure that all .cpp files are listed.
  3. Clear the Visual Studio caches. If you modify files while VS is running, it may throw errors because of the caches. Close VS, then delete the .vs directory (it's hidden), and also the build outputs: Debug, Release, and x64 if any of them exist.

Given your three visible errors, the problematic files are imgui_tables.cpp and imgui_widgets.cpp where those unresolved functions are defined. There may be more, however, since there's 56 other errors.

*TL;DR: Possible fixes are at the bottom of this comment.* In your case, you're getting a lot of LNK2001 errors. This is the linker telling you, "You've used this function, but I can't find its definition". I'm going to clear up a misconception here: > it takes me right to the imgui.cpp to the proper function That's a header file in your screenshot, not a source file as you thought. A header file, which has the extension `.h` or (less commonly) `.hpp`, contains the function name, return type, and parameters. This is known as its signature. After the signature, there's just a semicolon. This is what we're seeing in your screenshot. A source file, which has the extension `.cpp`, reiterates the function signature, but it also adds the function body, enclosed in `{` and `}`. This is the function's definition. For example, take this sample header file: ```cpp // myheader.h int myFunction(); ``` What would you say if I were to ask you, "What would happen if we were to call `int x = myFunction();`? What would `x` be?" Of course, you wouldn't be able to answer properly because you don't know what's inside of the function, you only know that it exists and returns some unspecified int. By defining it in another source file, it becomes clear what the function does: ```cpp // mysource.cpp int myFunction() { std::cout << "Hello\n"; return 4; } ``` This is what's happening when you get LNK2001 or LNK2019. In your screenshot, we're asking MSVC "What would happen if we called `ImGui::EndColumns()`?" but we didn't provide the source file that it's defined in; we only provided the header file shown in your screenshot. This causes the linker to fail. There are several possible fixes to this issue: 1. **Make sure you've updated all your files.** You may be trying to compile an old file that doesn't have the needed function definition. 2. **Check that all your files are being included during compile.** You can go into your Solution Explorer in Visual Studio and make sure that all `.cpp` files are listed. 3. **Clear the Visual Studio caches.** If you modify files while VS is running, it may throw errors because of the caches. Close VS, then delete the `.vs` directory (it's hidden), and also the build outputs: `Debug`, `Release`, and `x64` if any of them exist. Given your three visible errors, the problematic files are `imgui_tables.cpp` and `imgui_widgets.cpp` where those unresolved functions are defined. There may be more, however, since there's 56 other errors.
pp9999 commented 2021-07-16 16:09:26 +00:00 (Migrated from github.com)

I found out 2 things, first I forgot to add "mgui_tables.cpp and imgui_widgets.cpp"..... All solved

I found out 2 things, first I forgot to add "mgui_tables.cpp and imgui_widgets.cpp"..... All solved
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#4328
No description provided.