This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linking header files into projects - Error "Could not open source file"



Hi

I'm having trouble with header files linked (rather than added) to a project.

My expectation of this function is that the linked header file is effectively part of the current project (just like a local copy of the file) and hence I do not need to add an include path for that header.

I link both the .h and .c files to my project, then add a corresponding #include in one of the other project files.

For example, I link "adc.h" and "adc.c" to my project, then in processData.c I add  #include "adc.h"

If I ctrl+click on adc.h in the #include (or press F12) CCS opens the correct file, so CCS knows where the file is.

But, if I build the project, I get the error ' #5 could not open source file "adc.h" '.

Can anyone explain what I'm doing wrong?

OS: Windows 7, SP1, 64bit,  CCS: 6.0.1.00040 , Device: LM3S9D96

Regards

Julian

  • Hi Julian,

         Right Click your project at project explorer and add that c file (e.g adc.c), then compile.

    - kel

  • G'Day Kel,

    adc.c is already linked to the project (rather than copied into the project).

    The project compiles fine if the path to adc.c and adc.h is added to the include path.

    If I remove this path, I get the error. 

    I guess my question is why do I need to make this change to the include path.  I would have thought linking the files to the project woule be enough. 

    Cheers

    Julian.

  • Hi Julian,

    when you link a file the IDE stores only a reference to that file.  Therefore you do need to tell CCS where the file is.   As mentioned in the other response ... adding a file with copy into project does not require this.

    Please see

    http://processors.wiki.ti.com/index.php/Include_paths_and_options

    Linked resources are not copied at all ...that is exactly how a linked reference is defined.

    Best regards,

    Lisa

  • Hi Lisa,

    Thanks for that information.  I appreciate your time.

    Unfortunately I'm still confused.

    I understand you are saying that a reference to the file, not the file itself is added when you add a link. 

    What is the point of that?  How do you use linked files?

    My understanding was that the only difference between adding a copy and adding a link is the location of the target file.  Otherwise they are 100% the same by CCS.  Clearly that's not the case!

    What I want to do is explicitly add one or two centrally stored/controlled library files (.c & .h) to my project rather than broadly including everything using include paths etc.  Adding as a link seemed to be the way to do that but obviously its not.  Is there another way? 

    Cheers

    Julian

     

  • Julian,

    I think the problem is a more general problem and not entirely related to CCS. Let me try to explain:

    A compiler in an IDE looks for all source code files in a project (*.c and/or *.asm) and tries to compile /assemble them into object files.  A header-file (*.h) is dealt with differently, as it is no source code file in close sense. A header file usually contains only prototypes, decalartions of data types, #defines etc - in summary nothing that leads to object code.  Therefore a *.h - File, added to a project (copied or linked) will not be touched by the compler.

    If  a C-file has a #include *.h statement - the pre-compiler is forced to search that file - and therfore we have to provide the correct include search paths.

    In your last post you spoke about addiing library files (.c &..h). These two file types have nothing to do with library files - a library file is a *.lib file. Such a precompiled library - object  (*.lib) will be added by the Linker to the final machine code. So if a *.lib file is part of a project, let it be copied or linked, it will be dealt with by the Linker. If other parts of the project call a library function, this machine code function will be taken from the lib-file and added to the final machine code. To be able for your code to call a library function, you will need to provide another header-file, again by using a #include in one of your c-code files and a correct setup of the include search path.

    Best Regards

    Frank

  • Hi Julian,

    to add to Franks response ... the reason for linking instead of simply copying/direclty including.

    Imagine you have multiple projects for the same target device.   You can guess it likely there will be libraries or some bits of source code that would be great to recycle.  This is the point.   You can leave these 'common' items somewhere, simply 'link' them to your project and then you don't need a copy of it for each project and any updates and changes ... again you need not think which project has the changes or not.  This is why you would pass a reference rather than a copy of the file.

    Also ... Frank make some good points .. eg different handling of headers and libraries.

    Best regards,
    Lisa

  • Frank Bormann said:

    If  a C-file has a #include *.h statement - the pre-compiler is forced to search that file - and therfore we have to provide the correct include search paths.

    To add to Frank's comment, the rules used by the compiler to search for a header file included with #include statement is documented in the Compiler Users Guide. As an example, here is a link to a MSP430 Compiler Users Guide that explains it (see section 2.5.2). Also here is a link to a quick tip video that talks about #include and search paths. Hope this helps.

  • Thank you Lisa, Frank & AartiG

    Frank's description, and the compile guide AartiG pointed out explain why links won't work as I expect for .h files.

    What Lisa describes is exactly what I'm trying to do.

    Multiple projects targeting the same device sharing common, centrally stored and maintained source code libraries (i.e. .c & .h files, not .lib as pointed out by Frank). 

    But, in addition, I wanted to be explicit about every file I pulled in from the central source code library.  This would make it easier for me to take a snapshot (e.g. zip of source files) of all the code in the project that has not come from 3rd party libraries. 

    From Frank's description it sounds like I need to divide up my central library into source and include directories.  The source files can be added to the project as links, and the include directory is added to the include path.

    This is not ideal for me because the include path makes it hards to work out which .h files are pulled in.

    The more I think about it, the more I realise that the best solution is to do linking externally to CCS.  Since we are using SVN, windows hard links/symlinks are out.  That leave SVN externals as the way to go I think.


    Regards

    Julian

  • Julian,

    regarding:

    "From Frank's description it sounds like I need to divide up my central library into source and include directories.  The source files can be added to the project as links, and the include directory is added to the include path."

    What you also can do is to create a subfolder "include" in your project, then make a copy of all needed *.h -files into this subfolder and provide a single include search path ".\include" in the project options. That  way you can export the whole project into a zip-file, including all of the header-files in use. If you also copy the used *.lib files in a similar way, the zip -file will contain everything.

    Frank