couldn't compile with libraries projects

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

couldn't compile with libraries projects

1,281 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miccio on Fri Apr 15 08:12:26 MST 2016
Hello fellow LPC-users,

I have a workspace composed of the following projects:
- a hardware abstraction layer project (C++ static library project) -> HAL
- a modules/middleware project (C++ static library project) -> MOD
- a final application (C++ project) -> MAIN
- the LPCOpen chip layer (lpc_chip_15xx) -> LPCOPEN

The following graph expresses the relation between these projects:
      MAIN_______
     /    \      \
    MOD   HAL  LPCOPEN
     |     |
    HAL LPCOPEN
     |
  LPCOPEN


Compilation of both HAL and MOD occurs successfully, however when I try to compile the MAIN project, I get these linker errors:
Building target: lpc1549_main.axf
Invoking: MCU C++ Linker
arm-none-eabi-c++ -nostdlib -L"WORKSPACEPATH/lpc_chip_15xx/Debug" -L"WORKSPACEPATH/CMSIS_DSPLIB_CM3/lib" -L"WORKSPACEPATH/lpc1549_modules/Debug" -L"WORKSPACEPATH/lpc1549_hal/Debug" -Xlinker -Map="lpc1549_main.map" -Xlinker --gc-sections -Xlinker -print-memory-usage -mcpu=cortex-m3 -mthumb -T "lpc1549_main_Debug.ld" -o "lpc1549_main.axf"  ./src/sys/cr_cpp_config.o ./src/sys/cr_startup_lpc15xx.o ./src/sys/crp.o ./src/sys/sysinit.o  ./src/main.o   -llpc_chip_15xx -lCMSIS_DSPLIB_CM3 -llpc1549_modules -llpc1549_hal
WORKSPACEPATH/lpc1549_hal/Debug/liblpc1549_hal.a(spi.o): In function `Chip_SWM_MovablePortPinAssign':
WORKSPACEPATH/lpc_chip_15xx/inc/swm_15xx.h:234: undefined reference to `Chip_SWM_MovablePinAssign'
WORKSPACEPATH/lpc1549_hal/Debug/liblpc1549_hal.a(spi.o): In function `SPI::init(PortPin, PortPin, PortPin, PortPin, LPC_SPI_T*)':
WORKSPACEPATH/lpc1549_hal/Debug/../src/spi.cpp:63: undefined reference to `Chip_SPI_Init'
WORKSPACEPATH/lpc1549_hal/Debug/liblpc1549_hal.a(spi.o): In function `SPI::initSettings()':
WORKSPACEPATH/lpc1549_hal/Debug/../src/spi.cpp:114: undefined reference to `Chip_SPI_CalClkRateDivider'
WORKSPACEPATH/lpc1549_hal/Debug/../src/spi.cpp:131: undefined reference to `Chip_SPI_SetConfig'
WORKSPACEPATH/lpc1549_hal/Debug/../src/spi.cpp:132: undefined reference to `Chip_SPI_DelayConfig'
collect2: error: ld returned 1 exit status
make: *** [lpc1549_main.axf] Error 1


It is basically complaining about any non-inlined LPCOpen function used inside those HAL project functions used in the MAIN project (hope it's not too convoluted).
It would also complain about any non-inlined LPCOpen function used inside those HAL project functions used in the MOD project functions used in the MAIN project (ok, that sure is a little convoluted, but should be easy to get from the graph above).

The projects have been created using the LPCXpresso wizard, and the libraries have been included using this guideline: https://www.lpcware.com/content/faq/lpcxpresso/creating-linking-library-projects

Any idea about what could be causing the issue?
Thanks in advance and have a nice weekend!
标签 (1)
0 项奖励
回复
4 回复数

1,216 次查看
lpcware
NXP Employee
NXP Employee
bump
0 项奖励
回复

1,216 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miccio on Tue Apr 26 05:05:39 MST 2016
Hi again everyone,

I finally figured out the problem and now I can successfully compile the project!
I am writing here my discoveries for future reference's sake

According to the GCC docs,

Quote:

-llibrary
-l library
    Search the library named library when linking.
    (The second alternative with the library as a separate argument
    is only for POSIX compliance and is not recommended.)

    It makes a difference where in the command you write this option;
    the linker searches and processes libraries and object files in the
    order they are specified.
    Thus, `foo.o -lz bar.o' searches library `z' after file foo.o but
    before bar.o. If bar.o refers to functions in `z', those functions
    may not be loaded.



Unfortunately LPCXpresso's "smart update" ain't that smart, so you have to sort the libraries by yourself
I found that the easiest and fastest way to do so is by means of editing the .cproject file inside the main project folder: all it takes is to reorder the listOptionValue entries from
option [...]
listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/inc}""
listOptionValue builtIn="false" value=""${workspace_loc:/lpc_chip_15xx/inc}""
listOptionValue builtIn="false" value=""${workspace_loc:/CMSIS_DSPLIB_CM3/inc}""
listOptionValue builtIn="false" value=""${workspace_loc:/lpc1549_modules/inc}""
listOptionValue builtIn="false" value=""${workspace_loc:/lpc1549_hal/inc}""
/option

to
option [...]
listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/inc}""
listOptionValue builtIn="false" value=""${workspace_loc:/CMSIS_DSPLIB_CM3/inc}""
listOptionValue builtIn="false" value=""${workspace_loc:/lpc1549_modules/inc}""
listOptionValue builtIn="false" value=""${workspace_loc:/lpc1549_hal/inc}""
listOptionValue builtIn="false" value=""${workspace_loc:/lpc_chip_15xx/inc}""
/option


Please note that this has to be done for all the occurrences of the libraries - there should be a dozen or so.

Happy coding!!
0 项奖励
回复

1,216 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miccio on Tue Apr 26 03:42:42 MST 2016
Hi C6H,

and thank you for the hint.

I went through the header files and they all seem to include the extern "C" guards.
I also thought about a name mangling issue, but it seems like the linker is complaining about something else :(

Any other idea?
Thanks in advance!
0 项奖励
回复

1,216 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by C6H6 on Fri Apr 15 09:07:03 MST 2016
This problem might be missing extern "C" guards.

This means "Use C style linking instead of C++ style linking".

Go to header files include function: Chip_SWM_MovablePinAssign, and add this code after #include header  guards (Ex. #ifdef __SPI_17XX_40XX_H_)

#ifdef __cplusplus
extern "C" {
#endif


And go to #endif for #include guards, (Ex. #endif /* __SPI_17XX_40XX_H_ */) and add this line.

#ifdef __cplusplus
}
#endif


Then, linker recognizes function 'Chip_SWM_MovablePinAssign' successfully.

You will add these 'extern "C"' s for all header that linker fails to find symbols.

I hope this tip can help you.

Best Regards.
0 项奖励
回复