graphitemaster / incbin

Include binary files in C/C++
The Unlicense
967 stars 90 forks source link

link error: undefined symbols #3

Closed ptrv closed 9 years ago

ptrv commented 9 years ago

I have a link error if I use INCBIN

I have a data.cpp file with this:

#include "incbin.h"

INCBIN(Icon, "Icon.png");

const unsigned char* an_icon = gIconData;

and in my main.cpp I try to access

extern const unsigned char* an_icon;

int main()
{
    const unsigned char* icon = an_icon;
    return 0;
}

I get link error that gIconData is not defined.

When I change incbin.h to the following it works:

diff --git a/incbin.h b/incbin.h
index 85be21a..9c7330e 100644
--- a/incbin.h
+++ b/incbin.h
@@ -95,16 +95,16 @@
  */
 #define INCBIN(NAME, FILENAME) \
     __asm__(INCBIN_SECTION \
-            INCBIN_GLOBAL(g ## NAME) \
-            INCBIN_TYPE(g ## NAME) \
+            INCBIN_GLOBAL(g ## NAME ## Data) \
+            INCBIN_TYPE(g ## NAME ## Data) \
             ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n" \
-            INCBIN_MANGLE "g" #NAME ":\n" \
+            INCBIN_MANGLE "g" #NAME "Data:\n" \
                 ".incbin \"" FILENAME "\"\n" \
             INCBIN_GLOBAL(g ## NAME ## Size) \
             INCBIN_TYPE(g ## NAME ## Size) \
             ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n" \
             INCBIN_MANGLE "g" #NAME "Size:\n" \
-                INCBIN_INT INCBIN_MANGLE "g" #NAME "Size - " INCBIN_MANGLE "g" #NAME "\n" \
+                INCBIN_INT INCBIN_MANGLE "g" #NAME "Size - " INCBIN_MANGLE "g" #NAME "Data\n" \
     ); \
     INCBIN_EXTERN(NAME)

With this I still get the same error if I use INCBIN_EXTERN(Icon) instead of my own extern const unsigned char* an_icon;

graphitemaster commented 9 years ago

When I was reworking the code for XCode name mangling issues I must've forgot about the "Data" suffix there. Fixed in master. Thanks.