Thread: codeblocks ide multiple files

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    662

    codeblocks ide multiple files

    i have copied the multiple file program out of the book. when i come to compile/build the program i get an error saying undefined reference to "clear_line()" (a function with in the program). the function is defined in the line.h file written in the line.c file and i have included the line.h in both main file and line.c file. as per the book.

    if i try and build either line.c or word.c seperatly by right clicking on them i get a pop up message box saying "that file isnt assigned to any target"

    what am i doing wrong
    many thanks
    coop

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,452
    It looks like you failed to create a project before you added your files to the IDE.

  3. #3
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    i created a new console project via the wizard and then added extra header files and source files by going to file.... new ......file
    was this wrong?

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,452
    Please post (as text) your project .cbp file. This file should show the different source files that are part of the project.

  5. #5
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    is this what you meant sorry for being thick,,,,,
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <CodeBlocks_project_file>
        <FileVersion major="1" minor="6" />
        <Project>
            <Option title="justify" />
            <Option pch_mode="2" />
            <Option compiler="gcc" />
            <Build>
                <Target title="Debug">
                    <Option output="bin/Debug/justify" prefix_auto="1" extension_auto="1" />
                    <Option object_output="obj/Debug/" />
                    <Option type="1" />
                    <Option compiler="gcc" />
                    <Compiler>
                        <Add option="-g" />
                    </Compiler>
                </Target>
                <Target title="Release">
                    <Option output="bin/Release/justify" prefix_auto="1" extension_auto="1" />
                    <Option object_output="obj/Release/" />
                    <Option type="1" />
                    <Option compiler="gcc" />
                    <Compiler>
                        <Add option="-O2" />
                    </Compiler>
                    <Linker>
                        <Add option="-s" />
                    </Linker>
                </Target>
            </Build>
            <Compiler>
                <Add option="-Wall" />
            </Compiler>
            <Unit filename="line.c">
                <Option compilerVar="CC" />
                <Option target="&lt;{~None~}&gt;" />
            </Unit>
            <Unit filename="line.h" />
            <Unit filename="main.c">
                <Option compilerVar="CC" />
            </Unit>
            <Unit filename="word.c">
                <Option compilerVar="CC" />
                <Option target="&lt;{~None~}&gt;" />
            </Unit>
            <Unit filename="word.h" />
            <Extensions>
                <code_completion />
                <debugger />
            </Extensions>
        </Project>
    </CodeBlocks_project_file>

  6. #6
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,728
    When you added those source files to the project, you had to choose a target (typically either Debug, Release or both), but for some reason you didn't... Remove the files from the project and re-add them. It should prompt you on what target you want.
    Devoted my life to programming...

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    4,452
    Okay, it looks like all the files are there, but it looks like you failed to add the files to the project. So basically what you need to do is remove the files from the project then re-add them to the project (Project-Add Files) and be sure to click the "Select All" button and then "OK" from the Multi Selection window.

  8. #8
    Registered User
    Join Date
    Apr 2019
    Posts
    662
    ok thanks guys it all compiles OK now. I know now for future reference. Im unsur why the options wernt ticked the first time as when i added them the second time all options were seleced

    many thanks
    coop

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. header files and multiple files
    By Dedalus in forum C Programming
    Replies: 5
    Last Post: 06-16-2009, 09:21 AM
  2. Multiple Source Files, make files, scope, include
    By thetinman in forum C++ Programming
    Replies: 13
    Last Post: 11-05-2008, 11:37 PM
  3. Packed Files (Puting multiple files in one file)
    By MrKnights in forum C++ Programming
    Replies: 17
    Last Post: 07-22-2007, 04:21 PM
  4. Replies: 1
    Last Post: 05-01-2003, 02:52 PM
  5. Multiple C++ Files
    By Sekti in forum C++ Programming
    Replies: 1
    Last Post: 02-27-2002, 09:51 PM

Tags for this Thread