public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* undefined reference when linking against glib-2.0
@ 2019-02-10 10:28 C.J. Wagenius
  2019-02-10 22:17 ` René Berber
  0 siblings, 1 reply; 2+ messages in thread
From: C.J. Wagenius @ 2019-02-10 10:28 UTC (permalink / raw)
  To: cygwin


 Hi.

 I'm trying to compile the following source file
---
#include <glib.h>
#include <stdio.h>

int main(int argc, char **argv)
{
  int *a;

  a = g_new(int, 1);
  g_free(a);

return 0;
}
---
... and get linking errors.

$ gcc -Wl,--verbose -o testa `pkg-config --cflags --libs glib-2.0` test.c
/tmp/ccHtEBvg.o:test.c:(.text+0x1e): undefined reference to `g_malloc_n'
/tmp/ccHtEBvg.o:test.c:(.text+0x2e): undefined reference to `g_free'
collect2: error: ld returned 1 exit status

(attempt to open /usr/lib/gcc/i686-pc-cygwin/7.4.0/../../../libglib-2.0.dll.a succeeded)

Windows 7 64-bit using 32-bin Cygwin. glib-2.0 (2.54.3-1) libraries and devel packages are installed.

What am I missing?

I've tried with 64-bin Cygwin too.

$ gcc -Wl,--verbose -o testa `pkg-config --cflags --libs glib-2.0` test.c
/tmp/ccyW0KzO.o:test.c:(.text+0x1f): undefined reference to `g_malloc_n'
/tmp/ccyW0KzO.o:test.c:(.text+0x1f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `g_malloc_n'
/tmp/ccyW0KzO.o:test.c:(.text+0x2f): undefined reference to `g_free'
/tmp/ccyW0KzO.o:test.c:(.text+0x2f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `g_free'

$  gcc -Wl,--verbose -o testa `pkg-config --cflags --libs glib-2.0` -m32 test.c In file included from /usr/lib/glib-2.0/include/glibconfig.h:9:0,
                 from /usr/include/glib-2.0/glib/gtypes.h:32,
                 from /usr/include/glib-2.0/glib/galloca.h:32,
                 from /usr/include/glib-2.0/glib.h:30,
                 from test.c:2:
/usr/include/glib-2.0/glib/gtypes.h: In function '_GLIB_CHECKED_ADD_U64':
/usr/include/glib-2.0/glib/gmacros.h:232:53: error: size of array '_GStaticAssertCompileTimeAssertion_0' is negative
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
                                                     ^
/usr/include/glib-2.0/glib/gmacros.h:229:47: note: in definition of macro 'G_PASTE_ARGS'
#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
                                               ^~~~~~~~~~~
/usr/include/glib-2.0/glib/gmacros.h:232:44: note: in expansion of macro 'G_PASTE'
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
                                            ^~~~~~~
/usr/include/glib-2.0/glib/gtypes.h:423:3: note: in expansion of macro 'G_STATIC_ASSERT'
   G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64));
   ^~~~~~~~~~~~~~~

I'm obviously doing something wrong. Thanks for help.

/cjw

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: undefined reference when linking against glib-2.0
  2019-02-10 10:28 undefined reference when linking against glib-2.0 C.J. Wagenius
@ 2019-02-10 22:17 ` René Berber
  0 siblings, 0 replies; 2+ messages in thread
From: René Berber @ 2019-02-10 22:17 UTC (permalink / raw)
  To: cygwin

On 2/10/2019 4:28 AM, C.J. Wagenius wrote:

> gcc -Wl,--verbose -o testa `pkg-config --cflags --libs glib-2.0` test.c

Try: gcc -o testa test.c `pkg-config --cflags --libs glib-2.0`

Its the way the compiler works under Windows (i.e. no unresolved
references, and the order of searching for them).

HTH
-- 
R.Berber


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-10 22:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-10 10:28 undefined reference when linking against glib-2.0 C.J. Wagenius
2019-02-10 22:17 ` René Berber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).