• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Trading Card Game 2 protagonist in the poll by clicking here.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Adding a New Source File

  • 55
    Posts
    15
    Years
    • Seen Feb 1, 2023
    I'm trying to add a new source file to the build; I followed the instructions here (just this section) to add the files to ld_script.txt, but I still get <function> used but not defined (it's declared in the .h file and used elsewhere) -- the .c implementation doesn't seem to be included.

    Anyone know how to add a new .c implementation correctly?

    Thanks in advance :)
     
    I'm trying to add a new source file to the build; I followed the instructions here (just this section) to add the files to ld_script.txt, but I still get <function> used but not defined (it's declared in the .h file and used elsewhere) -- the .c implementation doesn't seem to be included.

    Anyone know how to add a new .c implementation correctly?

    Thanks in advance :)

    Adding the new source file in ld_script.txt is all you need to do.
    Did you perhaps forget to include the .h file in the file where you are using the function?
     
    Thanks for the reply!

    (moved this bit into a spoiler because I've been able to move past this piece of the issue.)
    Spoiler:


    ---

    In terms of including the .h file, I do see it included. I even commented out the include in the spot where I call my functions, and the errors change to the following (as expected):
    Code:
    src/battle_main.c: In function `CreateNPCTrainerParty':
    src/battle_main.c:1916: warning: implicit declaration of function `Test'

    Which, to me, means it WAS being included properly, but it still doesn't explain why I still can't link/compile/etc. after adding the files to ld_script.txt.


    Any further ideas are appreciated :)

    ---

    Edit: do I need to add my new file under .text, .rodata, or both? Am I missing any other sections?

    Also note that I deliberately took out a comma in my new .c file to cause a syntax error, but the compiler DOES NOT pick it up -- it seems to be ignoring that file, but I can't figure out why...

    In the meantime, I'm stuck with a bunch of these warnings:
    Code:
    include/test.h:19: warning: 'Test' used but never defined
     
    Last edited:
    Thanks for the reply!

    (moved this bit into a spoiler because I've been able to move past this piece of the issue.)
    Spoiler:


    ---

    In terms of including the .h file, I do see it included. I even commented out the include in the spot where I call my functions, and the errors change to the following (as expected):
    Code:
    src/battle_main.c: In function `CreateNPCTrainerParty':
    src/battle_main.c:1916: warning: implicit declaration of function `Test'

    Which, to me, means it WAS being included properly, but it still doesn't explain why I still can't link/compile/etc. after adding the files to ld_script.txt.


    Any further ideas are appreciated :)

    ---

    Edit: do I need to add my new file under .text, .rodata, or both? Am I missing any other sections?

    Also note that I deliberately took out a comma in my new .c file to cause a syntax error, but the compiler DOES NOT pick it up -- it seems to be ignoring that file, but I can't figure out why...

    In the meantime, I'm stuck with a bunch of these warnings:
    Code:
    include/test.h:19: warning: 'Test' used but never defined

    If you can get the rom to compile you can search for the name of your file in the pokeemerald.map file to see if it is actually getting added to the rom, but it certainly sounds like it isn't.
    I'm not sure what would cause this but maybe you should post the contents of your ld_script.txt file and the new files you created so that any possible errors in them could be spotted.

    Regarding the sections, you should have both .text and .rodata sections for your file. If you want to create global variables in ewram, you will also need the ewram_data section, which you can get by including your new file in sym_ewram.txt.
     
    I get the feeling this is the root of my problems:
    Code:
    Assembler messages:
    Error: can't open src/random_party.s for reading: No such file or directory
    Makefile:274: recipe for target 'build/emerald/src/test.o' failed

    Here's how everything is set up:
    src/test.c
    Spoiler:



    src/includes/test.h
    Spoiler:



    src\battle_main.c
    Spoiler:





    All the code has been tested inside src\battle_main.c and works, but when I tried to split it into a new file, it doesn't seem to be included in with the build (I assume it's the reason the .s file can't be found, per the error at the top.)


    Thanks again for all the help! :)
     
    I get the feeling this is the root of my problems:
    Code:
    Assembler messages:
    Error: can't open src/random_party.s for reading: No such file or directory
    Makefile:274: recipe for target 'build/emerald/src/test.o' failed

    Here's how everything is set up:
    src/test.c
    Spoiler:



    src/includes/test.h
    Spoiler:



    src\battle_main.c
    Spoiler:





    All the code has been tested inside src\battle_main.c and works, but when I tried to split it into a new file, it doesn't seem to be included in with the build (I assume it's the reason the .s file can't be found, per the error at the top.)


    Thanks again for all the help! :)

    CustomRnd cannot be used outside test.c because it's declared as static.
     
    CustomRnd cannot be used outside test.c because it's declared as static.

    Well, I feel stupid. 😅😱 (I had even looked up what static means, but obviously picked the wrong resource). I removed all the static references, but the .c file is STILL not being compiled 🙄🙄.

    Spoiler:


    Edit: I also don't see a file named pokeemerald.map (I ran find . -name "pokeemerald.map" with no results).
     
    Last edited:
    Well, I feel stupid. 😅😱 (I had even looked up what static means, but obviously picked the wrong resource). I removed all the static references, but the .c file is STILL not being compiled 🙄🙄.

    Spoiler:

    Since the errors don't have any line numbers, I'd recommend commenting out/deleting all the code you've added and gradually adding it back in while compiling the project to figure out what is causing the errors.
    Start simple and try to get the file added before any actual code. For reference, here's a barebones example of modifications made to add a simple file which compiles and works fine.

    src/test.c
    Spoiler:


    include/test.h
    Spoiler:


    ld_script.txt diff
    Spoiler:


    sym_ewram.txt diff
    Spoiler:


    src/battle_main.c diff
    Spoiler:


    Edit: I also don't see a file named pokeemerald.map (I ran find . -name "pokeemerald.map" with no results).
    Did you rename the build to something other than pokeemerald? The .map file should appear alongside the .gba file when you build the project.
     
    Back
    Top