From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15244 invoked by alias); 2 Sep 2012 22:50:55 -0000 Received: (qmail 15235 invoked by uid 22791); 2 Sep 2012 22:50:50 -0000 X-SWARE-Spam-Status: No, hits=-5.1 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,TW_LG X-Spam-Check-By: sourceware.org Received: from mail-iy0-f175.google.com (HELO mail-iy0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 02 Sep 2012 22:50:37 +0000 Received: by iaky10 with SMTP id y10so7775325iak.20 for ; Sun, 02 Sep 2012 15:50:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.212.10 with SMTP id ng10mr8914282igc.35.1346626236236; Sun, 02 Sep 2012 15:50:36 -0700 (PDT) Received: by 10.42.49.81 with HTTP; Sun, 2 Sep 2012 15:50:35 -0700 (PDT) In-Reply-To: <1346413874515-865274.post@n5.nabble.com> References: <1346413874515-865274.post@n5.nabble.com> Date: Sun, 02 Sep 2012 22:50:00 -0000 Message-ID: Subject: Re: Building library with extern data fails in GCC From: Jonathan Wakely To: HvW Cc: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2012-09/txt/msg00002.txt.bz2 On Aug 31, 2012 2:51 PM, "HvW" wrote: > > Hi, > > I am trying to create a library that handles the USART TX and RX data. The > buffer used for the TX and RX data I declared as extern as this needs to = be > specified by the application using the library. This works fine in Keil > ARM-MDK. Attempting to build this in the latest version of GCC shows the > following errors: > > C:\yagarto_cortex_m3\bin\arm-none-eabi-gcc =A0libhl_usart.o -mcpu=3Dcorte= x-m3 > -mthumb -nostartfiles -Tstm32f103x_xl_flash.ld > -Wl,-Map=3Dlib_usart.map,--cref,--no-warn-mismatch -L./lib/ -lm -lgcc -lc > ./lib/lib_stm3210x_xl_stdperiph.a -o lib_usart.elf > libhl_usart.o: In function `Libhl_Usart_Lib_Init': > libhl_usart.c:(.text+0x1a): undefined reference to `Libhl_Usart2_Tx_Buff' > libhl_usart.c:(.text+0x1e): undefined reference to `Libhl_Usart2_Tx_Buff' > libhl_usart.c:(.text+0x2c): undefined reference to `Libhl_Usart3_Tx_Buff' > libhl_usart.c:(.text+0x30): undefined reference to `Libhl_Usart3_Tx_Buff' > libhl_usart.c:(.text+0x3e): undefined reference to `Libhl_Uart4_Tx_Buff' > libhl_usart.c:(.text+0x42): undefined reference to `Libhl_Uart4_Tx_Buff' > libhl_usart.c:(.text+0x50): undefined reference to `Libhl_Uart5_Tx_Buff' > libhl_usart.c:(.text+0x54): undefined reference to `Libhl_Uart5_Tx_Buff' > libhl_usart.c:(.text+0x62): undefined reference to `Libhl_Usart1_Rx_Buff' > libhl_usart.c:(.text+0x66): undefined reference to > > > I am sure that I am just missing some compiler option that will allow it = to > assume that the data will be available when needed. > > I am attaching the code and makefile. I haven't looked at the code or makefile, but the command above doesn't tell gcc to build a library, it builds a final executable, or tries to. To create a shared library use the gcc option -shared, or to create a static library use ar instead of gcc.