microui icon indicating copy to clipboard operation
microui copied to clipboard

msvc c++ build failing to compile

Open Skytrias opened this issue 6 years ago • 8 comments

hey ive been looking into ui's and your library looks pretty nice. However im getting weird link errors and error: LNK2019 unresolved symbol ""void __cdecl mu_init(struct mu_Context *)" or when i inserted extern "C" myself in your files i got it to "mu_init" being unresolved.

my build.bat uses these libs gdi32.lib opengl32.lib winmm.lib

just wondering if anyone usese windows with msvc c++ here and got this figured out

Skytrias avatar Jun 25 '19 17:06 Skytrias

Have the same issue, not sure how to fix it...

AregevDev avatar Sep 06 '19 15:09 AregevDev

  1. initial empty vs2019 project
  2. set /SUBSYSTEM:WINDOWS flag
  3. add _CRT_SECURE_NO_WARNINGS flag
  4. put everything in the root folder of your project, or you may Configure Include Directories to include src and demo folder.
  5. use NuGet add SDL2 ~~and nupengl.core~~ (windows already has opengl) Or you may add those dependences by hand like: How do I link SDL with Visual Studio 2019 - Stack Overflow
  6. change include: In main.c: #include <SDL2/SDL.h> => #include "SDL.h" In renderer.c:
    • #include <SDL2/SDL.h> => #include "SDL.h";
    • #include <SDL2/SDL_opengl.h> => #include "SDL_opengl.h"
  7. add opengl32.lib to Additional Dependencies
  8. build and run!

inkydragon avatar Dec 16 '19 06:12 inkydragon

just wondering if anyone usese windows with msvc c++ here and got this figured out

You probably compiled your project as C++. Look, there's no:

#ifdef __cplusplus
extern "C" {
#endif

inside microui.h

gvanem avatar May 31 '20 13:05 gvanem

I tried @inkydragon 's suggestion but no luck. I'm not using VS, just invoking the compiler from a developer command prompt. Any ideas?

immortalx74 avatar Oct 09 '21 09:10 immortalx74

Your project is C++, right? Apply this simple patch:

--- a/src/microui.h 2021-10-09 12:10:12
+++ b/src/microui.h 2021-10-09 12:14:10
@@ -8,6 +8,10 @@
 #ifndef MICROUI_H
 #define MICROUI_H

+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define MU_VERSION "2.01"

 #define MU_COMMANDLIST_SIZE     (256 * 1024)
@@ -293,4 +297,8 @@
 void mu_begin_panel_ex(mu_Context *ctx, const char *name, int opt);
 void mu_end_panel(mu_Context *ctx);

+#ifdef __cplusplus
+};
+#endif
+
 #endif

gvanem avatar Oct 09 '21 10:10 gvanem

@gvanem I don't have a "project" as I'm not actually using Visual Studio. I invoke the compiler from the command line, and the default behavior with .c extensions is to compile as C. Even if I force C compilation with /Tc or /TC compiler flags, I always get the error:

LINK : fatal error LNK1561: entry point must be defined

I also tried with your fix and forcing C++ compilation, in which case I get several C4576 errors.

immortalx74 avatar Oct 09 '21 14:10 immortalx74

You don’t have a main / winmain function.

Le sam. 9 oct. 2021 à 16:54, immortalx74 @.***> a écrit :

@gvanem https://github.com/gvanem I don't have a "project" as I'm not actually using Visual Studio. I invoke the compiler from the command line, and the default behavior with .c extensions is to compile as C. Even if I force C compilation with /Tc or /TC compiler flags, I always get the error:

LINK : fatal error LNK1561: entry point must be defined

I also tried with your fix and forcing C++ compilation, in which case I get several C4576 errors.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rxi/microui/issues/13#issuecomment-939309730, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH5RYT42INKH5XMWGTCM3TUGBJRTANCNFSM4H3KSBCA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

g012 avatar Oct 09 '21 15:10 g012

Problem fixed. I was only compiling main.c and microui.c. I assumed that renderer.c was included in main.c

immortalx74 avatar Oct 09 '21 15:10 immortalx74