MODULE_LIBRARIES Not Working as Expected in XTC15 Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
vergil19
Member++
Posts: 21
Joined: Thu Jan 20, 2022 3:54 am

MODULE_LIBRARIES Not Working as Expected in XTC15

Post by vergil19 »

When attempting to use `MODULE_LIBRARIES` in the XTC15 environment, it appears to have no effect.

I am referring this xmos doc and try to build a test library and use it in an application.

The expected behavior is for the libraries defined in `MODULE_LIBRARIES` to be included during the build process, but this is not happening.

The file tree looks like this:

Code: Select all

sw_test
└── app_test_lib_module
    ├── Makefile
    ├── bin
    └── src
        └── main.xc
lib_rgb
├── api
│   └── misc_utils.h
├── lib
│   └── xs3a
│       └── librgb.a
└── module_build_info
The makefile looks like this:

Code: Select all

TARGET = XCORE-AI-EXPLORER

BUILD_FLAGS = -O2 -g -DDEBUG_PRINT_ENABLE=1 -report -fxscope

USED_MODULES = lib_rgb

MODULE_LIBRARIES = rgb

XCC_FLAGS = $(BUILD_FLAGS)
When I tried to compile app_test_lib_module, it occars that "Error: Undefined reference to 'reverse_buf' "

Code: Select all

$ xmake -j
Checking build modules
Using build modules: lib_rgb_copy(0.0.2)
Rebuild .build/_iflag.rsp
Analyzing main.xc
Rebuild .build/_pca.rsp
Propagating analysis
Creating dependencies for main.xc
Compiling main.xc
Rebuild .build/_obj.rsp
Creating app_test_lib_module.xe
../src/main.xc: Error: Undefined reference to 'reverse_buf'
xmake[1]: *** [bin//app_test_lib_module.xe] Error 1
xmake: *** [bin//app_test_lib_module.xe] Error 2
Attempted to manually include the libraries, which worked, indicating that the issue is specific to `MODULE_LIBRARIES`.

What I did was moving the header file and library to the app_test_lib/lib/, like this:

Code: Select all

lib
├── librgb.a
└── misc_utils.h
And I added these flag to BUILD_FLAGS, which works fine

Code: Select all

BUILD_FLAGS += -L../lib -lrgb -I../lib
Any insights or solutions to ensure `MODULE_LIBRARIES` works as intended in XTC15 would be greatly appreciated.


View Solution
User avatar
Ross
XCore Expert
Posts: 968
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Can you provide the module_build_info file from lib_rgb?

I should look a bit like this, I suspect (assuming you want one .a for xcore-200 and one for xcore.ai)

Code: Select all

# This module_build_info is for a module that builds to a library

# The LIBRARY variable needs to be set to the name of the library to
# be built

LIBRARIES =  rgb_x200 rgb_xai

#Default is xs1b
LIB_ARCH_rgb_x200 = xs2a
LIB_ARCH_rgb_xai = xs3a

# You can set flags specifically for your module by using the MODULE_XCC_FLAGS
# variable. So the following
#
#   MODULE_XCC_FLAGS = $(XCC_FLAGS) -O3
#
# specifies that everything in the modules should have the application
# build flags with -O3 appended (so the files will build at
# optimization level -O3).
#
# You can also set MODULE_XCC_C_FLAGS, MODULE_XCC_XC_FLAGS etc..

MODULE_XCC_FLAGS = $(XCC_FLAGS) -g -O3

LIB_XCC_FLAGS_rgb_x200 = -DMY_FLAG=1

LIB_XCC_FLAGS_rgb_xai = -DMY_FLAG=2

DEPENDENT_MODULES = 

EXCLUDE_FILES = 

# The EXPORT_SOURCE_DIRS variable are the directories that contain
# include files for the library and any source files that you do not
# want compiled into the library but supplied as source to the
# application using the module.
EXPORT_SOURCE_DIRS = src

OPTIONAL_HEADERS += rgb_conf.h

User avatar
vergil19
Member++
Posts: 21
Joined: Thu Jan 20, 2022 3:54 am

Post by vergil19 »

Ross wrote: Fri Nov 17, 2023 12:08 pm Can you provide the module_build_info file from lib_rgb?
Thanks for your reply! Here is my module_build_info file.

Code: Select all

VERSION = 0.0.2

DEPENDENT_MODULES = 

MODULE_XCC_FLAGS = $(XCC_FLAGS) -g -O3 -Wall -Wextra -Werror

EXPORT_INCLUDE_DIRS = api

LIB_ARCH := xs3a

LIB_XCC_FLAGS_rgb = -g -O3 -Wall -Wextra -Werror

LIBRARY = rgb

EXPORT_SOURCE_DIRS = api
User avatar
vergil19
Member++
Posts: 21
Joined: Thu Jan 20, 2022 3:54 am

Post by vergil19 »

I am so excited that I finally solve it by modify `build/xcommon/module_xcommon/build/Makefile.common1` Line 699&700 in XTC 15.2.1

The reason why the compiler can not found reverse_buf or librgb.a is that it does not search the library files while I ONLY have `xs3a` in my `lib` folder.

After I added the key word in makefile, it works just fine.

original:

Code: Select all

IS_LIB_DIR = $(strip $(call WILDCARD,$1/xs1b/lib*.a) $(call WILDCARD,$1/xs2a/lib*.a))
LIB_FILES := $(foreach x, $(FULL_LIB_DIRS), $(call WILDCARD,$x/xs1b/lib*.a)) $(foreach x, $(FULL_LIB_DIRS), $(call WILDCARD,$x/xs2a/lib*.a))

modified:

Code: Select all

IS_LIB_DIR = $(strip $(call WILDCARD,$1/xs1b/lib*.a) $(call WILDCARD,$1/xs2a/lib*.a) $(call WILDCARD,$1/xs3a/lib*.a))
LIB_FILES := $(foreach x, $(FULL_LIB_DIRS), $(call WILDCARD,$x/xs1b/lib*.a)) \
             $(foreach x, $(FULL_LIB_DIRS), $(call WILDCARD,$x/xs2a/lib*.a)) \
             $(foreach x, $(FULL_LIB_DIRS), $(call WILDCARD,$x/xs3a/lib*.a))
Thank you Ross!
User avatar
Ross
XCore Expert
Posts: 968
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Oh great, I'll get that patch submitted internally, thanks!