Linking error: undefined reference BoyScoutUpdateSong()

thepursuer
Posts: 10
Joined: Sat Mar 11, 2023 5:53 am

Linking error: undefined reference BoyScoutUpdateSong()

Post by thepursuer » Sat Mar 11, 2023 6:12 am

I've just started programming for the GBA so I'm pretty late to the game. But if anybody is still lurking out there, maybe they can help me with a problem. I've been going through the examples (copy paste the files and build using cmake) and hit a wall with PlayBoyScout. I've set up my project to work with cmake:

Code: Select all

├── CMakeLists.txt
├── data
│   ├── ScoutSplash.pcx        
│   └── tune.bgf
└── src
    ├── CMakeLists.txt
    └── PlayBoyScout.cpp 
And my cmake files:

Code: Select all

# Specify the minimum version of CMake required
cmake_minimum_required(VERSION 3.16)

# Set the CMake toolchain file
list(APPEND CMAKE_MODULE_PATH C:/devkitPro/cmake)
include(GBA)
include(Platform/NintendoGBA)

# Set the project name and version
project(my_gba_project VERSION 1.0)

add_subdirectory(src)

Code: Select all

# Add all .c files in the src directory to the executable target
file(GLOB SOURCES *.cpp **/*.cpp)
add_executable(my_gba_executable ${SOURCES})

# dkp_add_embedded_binary_library(splash_lib ${SPLASH})
dkp_add_embedded_binary_library(bgf_target ${PROJECT_SOURCE_DIR}/data/tune.bgf)
dkp_add_embedded_binary_library(pcx_target ${PROJECT_SOURCE_DIR}/data/ScoutSplash.pcx)
# Set the linker directories for devkitPro
target_link_libraries(my_gba_executable PUBLIC mm gba pcx_target bgf_target)

gba_create_rom(my_gba_executable)
But I get linker errors stating undefined reference to anything BoyScout related. I've checked the libgba.a with nm and found that those symbols do infact exist in that library and I've linked it in the cmake file. irqInit(), for example seems to be defined. What could be happening here? Do I have some configuration errors?

WinterMute
Site Admin
Posts: 1989
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Linking error: undefined reference BoyScoutUpdateSong()

Post by WinterMute » Wed May 10, 2023 11:14 am

Would be better to add CMakeLists.txt to the existing project rather than copying the original files elsewhere. These files should not contain windows paths nor should they replicate what our existing cmake framework does. We're still working on documenting that & getting it right. I was able to build this particular example with this CMakeLists.txt in the root of the project.

Code: Select all

cmake_minimum_required(VERSION 3.13)

project(PlayBoyscout VERSION 1.0)

add_executable(PlayBoyScout ${PROJECT_SOURCE_DIR}/source/PlayBoyScout.c)

dkp_add_embedded_binary_library(bgf_target ${PROJECT_SOURCE_DIR}/data/tune.bgf)
dkp_add_embedded_binary_library(pcx_target ${PROJECT_SOURCE_DIR}/data/ScoutSplash.pcx)

target_link_libraries(PlayBoyScout PRIVATE pcx_target bgf_target gba)

gba_create_rom(PlayBoyScout)
This should be configured with the arm-none-eabi-cmake wrapper found in /opt/devitpro/portlibs/gba/bin from the msys2 shell we provide like this

Code: Select all

/opt/devkitpro/portlibs/gba/bin/arm-none-eabi-cmake -B build -S .
Please note: This needs to be run from the msys2 bash shell, it won't work properly from cmd, powershell etc. That shell identifies as MSYS_NT similar to this

Code: Select all

$ uname -a
MSYS_NT-10.0-19044 ashpool 3.4.6.x86_64 2023-04-01 11:43 UTC x86_64 Msys
you can then build using

Code: Select all

make -C build
Help keep devkitPro toolchains free, Donate today

Personal Blog

thepursuer
Posts: 10
Joined: Sat Mar 11, 2023 5:53 am

Re: Linking error: undefined reference BoyScoutUpdateSong()

Post by thepursuer » Thu Dec 28, 2023 4:19 am

Thank you for the reply! Unfortunately I shelved the project for a while and did not get a chance to read this. I did get it working on my own at the time via a different method but I didn't know about the arm-none-eabi-cmake though or the windows paths. I changed that up and I'm trying to solve a different problem now. It seems my generated cmake files still have windows paths even though I removed the windows style paths from cmakelists. I can run make once succesfully but subsequent runs fail. It seems to generated a compiler-depend.make file with windows paths:

Code: Select all

src/CMakeFiles/my_gba_executable.dir/main.o: /home/.../Development/GBA_project_template/src/main.cpp \
  src/C:/Users/.../Development/GBA_project_template/src/main.cpp \
  src/C:/devkitPro/devkitARM/arm-none-eabi/include/_newlib_version.h \
  src/C:/devkitPro/devkitARM/arm-none-eabi/include/machine/_default_types.h \
  src/C:/devkitPro/devkitARM/arm-none-eabi/include/stdint.h \
  src/C:/devkitPro/devkitARM/arm-none-eabi/include/sys/_intsup.h \
This causes the next run of make:

Code: Select all

src/CMakeFiles/my_gba_executable.dir/compiler_depend.make:4: *** multiple target patterns.  Stop.
make[1]: *** [CMakeFiles/Makefile2:98: src/CMakeFiles/my_gba_executable.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
I suspect this is because my project is in my user directory on windows and not in the mysys2 directory. A quick google search said that the windows colons cause issues in mysys2 or something. I'll try moving it into the devkitpro install directory and see what happens.
Edit: It did not help :(
Last edited by thepursuer on Thu Dec 28, 2023 4:21 am, edited 1 time in total.

WinterMute
Site Admin
Posts: 1989
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Linking error: undefined reference BoyScoutUpdateSong()

Post by WinterMute » Sun Dec 31, 2023 7:41 pm

The user directory should be fine unless there are spaces in the path.

It's difficult to know how to advise without seeing the project in question. Common issues are that people change the environment variables from the msys2 style paths to windows style paths or use a windows native cmake instead of the provided msys2 cmake.

Ideally if you could let us see the complete project and the output of env on your system (run env > env.txt from msys2 shell and redact anything personal you don't want to share)
Help keep devkitPro toolchains free, Donate today

Personal Blog

thepursuer
Posts: 10
Joined: Sat Mar 11, 2023 5:53 am

Re: Linking error: undefined reference BoyScoutUpdateSong()

Post by thepursuer » Tue Jan 23, 2024 10:04 am

Ok I figured out where the issue is occuring. It seems to be related to Cmake's FetchContent. Here is a reproducable example:

Code: Select all

# Specify the minimum version of CMake required
cmake_minimum_required(VERSION 3.25)
include(FetchContent)

# Set the project name and version
project(my_gba_project VERSION 1.0)

set(CMAKE_CXX_STANDARD 20)

# Set the CMake toolchain file
include($ENV{DEVKITPRO}/cmake/GBA.cmake)

FetchContent_Declare(
  libfixmath
  GIT_REPOSITORY https://github.com/PetteriAimonen/libfixmath
  GIT_TAG d308e466e1a09118d03f677c52e5fbf402f6fdd0
)
FetchContent_MakeAvailable(libfixmath)

target_compile_definitions(libfixmath PUBLIC
    FIXMATH_FAST_SIN
    FIXMATH_NO_64BIT
    FIXMATH_NO_CACHE
    FIXMATH_NO_HARD_DIVISION
    # FIXMATH_NO_OVERFLOW
    # FIXMATH_NO_ROUNDING
    # FIXMATH_OPTIMIZE_8BIT
)

add_executable(gbatest 
    main.cpp
)

target_link_libraries(gbatest PUBLIC libfixmath)

gba_create_rom(gbatest)
dkp_target_generate_symbol_list(gbatest)
main.cpp can be anything that compiles. It compiles exactly once using "arm-none-eabi-cmake -B build . && make -C build". The next make call fails with the error. This particular library compiles on linux so I don't see a reason for this behavior. I can probably get around this somehow but it would be nice if it worked.

WinterMute
Site Admin
Posts: 1989
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Linking error: undefined reference BoyScoutUpdateSong()

Post by WinterMute » Wed Jan 24, 2024 11:29 am

thepursuer wrote: Tue Jan 23, 2024 10:04 am Ok I figured out where the issue is occuring. It seems to be related to Cmake's FetchContent. Here is a reproducable example:
FetchContent requires latest cmake ((3.28.1) which might be an issue for people not using bleeding edge distros. If this is msys then you may want to update using pacman -Syu.

Code: Select all

# Set the CMake toolchain file
include($ENV{DEVKITPRO}/cmake/GBA.cmake)
We recommend not doing this - including the toolchain file within the CMakeLists.txt file changes how cmake behaves and causes interesting and hard to debug weirdness. Using the command line specified above is the preferred approach.

Code: Select all

/opt/devkitpro/portlibs/gba/bin/arm-none-eabi-cmake -B _build -S .
cmake --build _build
Help keep devkitPro toolchains free, Donate today

Personal Blog

thepursuer
Posts: 10
Joined: Sat Mar 11, 2023 5:53 am

Re: Linking error: undefined reference BoyScoutUpdateSong()

Post by thepursuer » Wed Jan 24, 2024 1:10 pm

Gotcha, I removed the include() from my cmake lists and used the script instead. Unfortunately it has not solved the issue. And it looks like the latest cmake package for mysys2 is version 25.1. I'm unfortuatnely not familiar with how to install the latest version manually using mysys2. Would it be better if I just used linux?However to be honest, FetchContent should be in version 25.1. Here it is in the 3.14 documentation.

If you don't have any other ideas, I think my best bet is going to be to check if it's installed first and if not, download and install it.

WinterMute
Site Admin
Posts: 1989
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Linking error: undefined reference BoyScoutUpdateSong()

Post by WinterMute » Thu Jan 25, 2024 12:18 am

thepursuer wrote: Wed Jan 24, 2024 1:10 pm However to be honest, FetchContent should be in version 25.1. Here it is in the 3.14 documentation.

If you don't have any other ideas, I think my best bet is going to be to check if it's installed first and if not, download and install it.
Sorry, you're right. Clearly I misread something earlier.

The latest msys2 cmake is 3.28.1, you should be able to grab that with pacman -Sy cmake from msys2 shell. It's worth running pacman -Syu regularly to make sure it's up to date.

The attached project is working fine for me on windows using

Code: Select all

/opt/devkitpro/portlibs/gba/bin/arm-none-eabi-cmake -B _build -S .
cmake --build _build
Attachments
cmake-test.tar.xz
(1 KiB) Downloaded 461 times
Help keep devkitPro toolchains free, Donate today

Personal Blog

thepursuer
Posts: 10
Joined: Sat Mar 11, 2023 5:53 am

Re: Linking error: undefined reference BoyScoutUpdateSong()

Post by thepursuer » Thu Jan 25, 2024 7:11 am

Hmmm after reruning pacman update, I got the latest cmake: 28.1. I tried your test project and it's still the same though. I can build a binary once and then after that I get the error. Here's the output of env:

Code: Select all

ProgramFiles(x86)=C:\Program Files (x86)
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
asl.log=Destination=file
NUMBER_OF_PROCESSORS=8
FPS_BROWSER_USER_PROFILE_STRING=Default
COLORTERM=truecolor
PROCESSOR_LEVEL=6
TERM_PROGRAM_VERSION=1.85.2
USERDOMAIN_ROAMINGPROFILE=<compname>
DEVKITPRO=/opt/devkitpro
PROGRAMFILES=C:\Program Files
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
OS=Windows_NT
HOMEDRIVE=C:
USERDOMAIN=<compname>
PWD=/home/<user>
USERPROFILE=C:\Users\<user>
VSCODE_GIT_ASKPASS_NODE=C:\Users\<user>\AppData\Local\Programs\Microsoft VS Code\Code.exe
ALLUSERSPROFILE=C:\ProgramData
CommonProgramW6432=C:\Program Files\Common Files
HOME=/home/<user>
USERNAME=<user>
LANG=en_US.UTF-8
COMSPEC=C:\Windows\system32\cmd.exe
GIT_ASKPASS=c:\Users\<user>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\askpass.sh
APPDATA=C:\Users\<user>\AppData\Roaming
SYSTEMROOT=C:\Windows
LOCALAPPDATA=C:\Users\<user>\AppData\Local
__COMPAT_LAYER=DetectorsAppHealth
DEVKITARM=/opt/devkitpro/devkitARM
COMPUTERNAME=<compname>
VSCODE_GIT_ASKPASS_EXTRA_ARGS=--ms-enable-electron-run-as-node
TERM=xterm-256color
LOGONSERVER=\\<compname>
ZES_ENABLE_SYSMAN=1
PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
VSCODE_GIT_IPC_HANDLE=\\.\pipe\vscode-git-aa2070ea95-sock
TEMP=/home/<user>/AppData/Local/Temp
SHLVL=1
PROCESSOR_REVISION=9e0a
DriverData=C:\Windows\System32\Drivers\DriverData
COMMONPROGRAMFILES=C:\Program Files\Common Files
DEVKITPPC=/opt/devkitpro/devkitPPC
SESSIONNAME=Console
PS1=\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[35m\]$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n\$ 
VSCODE_GIT_ASKPASS_MAIN=c:\Users\<user>\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\git\dist\askpass-main.js
CHROME_CRASHPAD_PIPE_NAME=\\.\pipe\crashpad_23612_PIVLLSCMYAKNPDOR
HOMEPATH=\Users\<user>
TMP=/home/<user>/AppData/Local/Temp
PATH=/opt/devkitpro/msys2/usr/bin:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/c/Program Files/dotnet:/c/Program Files/Git/cmd:/c/Program Files/CMake/bin:/home/<user>/AppData/Local/Microsoft/WindowsApps:/home/<user>/AppData/Local/Programs/Microsoft VS Code/bin
ProgramW6432=C:\Program Files
ORIGINAL_XDG_CURRENT_DESKTOP=undefined
WINDIR=C:\Windows
FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
PUBLIC=C:\Users\Public
SYSTEMDRIVE=C:
TERM_PROGRAM=vscode
ProgramData=C:\ProgramData
_=/opt/devkitpro/msys2/usr/bin/env
OLDPWD=/home/<user>/cmake-test


thepursuer
Posts: 10
Joined: Sat Mar 11, 2023 5:53 am

Re: Linking error: undefined reference BoyScoutUpdateSong()

Post by thepursuer » Thu Feb 01, 2024 12:26 am

Actually after some usage, this error occurs even without the fetch content call :/. It's probably something about my environmnet that is causing this. If I figure out what is wrong I'll post back with a solution.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest