Note that there are some explanatory texts on larger screens.

plurals
  1. POUndefined ref to X, despite libraries linked in correct order
    primarykey
    data
    text
    <p>I know there are many of these threads already, but none seem to apply to this problem.</p> <p>I have two projects, each using my Dodge library. One is a fairly large project using much of the library's functionality; the other is a small demo. The make files for each project are identical, and yet the small demo fails to link, with the following errors:</p> <pre><code>../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_read_ihdr': (.text+0x3bc): undefined reference to `crc32' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_read_ihdr': (.text+0x3d9): undefined reference to `crc32' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_write_ihdr': (.text+0x5b9): undefined reference to `crc32' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_write_ihdr': (.text+0x5d6): undefined reference to `crc32' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_init_deflate': (.text+0x9b1): undefined reference to `deflateInit_' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_init_inflate': (.text+0xa43): undefined reference to `inflateInit_' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_end_deflate': (.text+0xa9c): undefined reference to `deflateEnd' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_end_inflate': (.text+0xae0): undefined reference to `inflateEnd' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_inflate': (.text+0xb5f): undefined reference to `inflate' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_deflate': (.text+0xbe6): undefined reference to `deflate' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_write_idats': (.text+0xcb0): undefined reference to `compress' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_write_idats': (.text+0xccc): undefined reference to `crc32' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_write_idats': (.text+0xceb): undefined reference to `crc32' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_write_idats': (.text+0xd9d): undefined reference to `crc32' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_read_idat': (.text+0xe86): undefined reference to `crc32' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o): In function `png_read_idat': (.text+0xea5): undefined reference to `crc32' ../Dodge/Dodge/lib/libpnglite.a(pnglite.o):(.text+0xec1): more undefined references to `crc32' follow </code></pre> <p>The references refer to libz. I used to following command to link the binary:</p> <pre><code>g++ ./main.o -o demo -L../Dodge/Dodge/lib -L/usr/lib -lDodge -lX11 -lGLESv2 -lEGL -lpnglite -lz -lBox2D `sdl-config --libs` -lSDLmain -lSDL -lSDL_mixer </code></pre> <p>As you can see -lz comes after -lpnglite. The static libraries libz.a and libpnglite.a are located in ../Dodge/Dodge/lib. I've tried playing about with the order to no avail.</p> <p>If I remove the following line from the code it links successfully. Strangely, the same line exists in the larger project, which encounters no problems.</p> <pre><code> tex0 = pTexture_t(new Texture(node)); </code></pre> <p>Texture's constructor uses pnglite, and is not declared inline fyi (if that's relevant).</p> <p>Does anyone have any clue as to what might be happening here? I've been using C++ for years, and this is the first time in ages I've been stumped by a linker error.</p> <p>Here are the two make files:</p> <pre><code>DODGE_LOCATION = ../Dodge NAME = platformer CC = g++ CFLAGS = -std=c++0x -O3 -Wall `sdl-config --cflags` -DLINUX -g -DDEBUG INCL = -I$(DODGE_LOCATION)/Dodge/include LIBS = -L$(DODGE_LOCATION)/Dodge/lib -L/usr/lib -lDodge -lX11 -lGLESv2 -lEGL -lpnglite -lz -lBox2D `sdl-config --libs` -lSDLmain -lSDL -lSDL_mixer SRC = src OBJS = $(SRC)/Application.o \ $(SRC)/Item.o \ $(SRC)/GameLogic.o \ $(SRC)/GameSettings.o \ $(SRC)/main.o \ $(SRC)/Menu.o \ $(SRC)/MenuItem.o \ $(SRC)/Player.o \ $(SRC)/SoundFx.o \ $(SRC)/StartMenu.o all: $(OBJS) $(CC) $(OBJS) -o $(NAME) $(LIBS) $(OBJS): %.o: %.cpp $(CC) -c $(CFLAGS) $(INCL) $&lt; -o $@ clean: rm -f $(SRC)/*.o </code></pre> <p>and the one that doesn't link:</p> <pre><code>DODGE_LOCATION = ../Dodge NAME = demo CC = g++ CFLAGS = -std=c++0x -O3 -Wall `sdl-config --cflags` -DLINUX -g -DDEBUG INCL = -I$(DODGE_LOCATION)/Dodge/include LIBS = -L$(DODGE_LOCATION)/Dodge/lib -L/usr/lib -lDodge -lX11 -lGLESv2 -lEGL -lpnglite -lz -lBox2D `sdl-config --libs` -lSDLmain -lSDL -lSDL_mixer SRC = . OBJS = $(SRC)/main.o all: $(OBJS) $(CC) $(OBJS) -o $(NAME) $(LIBS) $(OBJS): %.o: %.cpp $(CC) -c $(CFLAGS) $(INCL) $&lt; -o $@ clean: rm -f $(SRC)/*.o </code></pre> <p>The two projects are located in the same level of the directory tree, and as you can see the make files are the same. I run the make utility from the same terminal (just cd to project's directory), meaning the environment vars are the same too. I can't think of any other factors that might differentiate the two projects. As I said, the offending line in the project that fails is also present in the project that succeeds. Am I missing something obvious here?</p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload