Thread: Circular dependency problem

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    932

    Circular dependency problem

    Hi,

    I'm trying to use the CGenericList class which is part of DirectShow.
    I included the file required for its use but I still get the error:

    error C2143: syntax error : missing ';' before '<'|
    The error means that the compiler can't find the class definition.

    So I figured that I must have a circular dependency problem but I don't know how to check for it?

    I tried '#pragma once' too but it's still the same error.

    CGenericList class (Windows)

    Code:
    #include <windows.h>
    
    #include <Streams.h>
    #include <Dshow.h>
    
    class CRouting {
    public:
        class CRouting       *pLeftRouting;
        class CRouting       *pRightRouting;
        LONG                 VideoInputIndex;
        LONG                 VideoOutputIndex;
        LONG                 AudioInputIndex;
        LONG                 AudioOutputIndex;
        IAMCrossbar         *pXbar;
        LONG                 InputPhysicalType;
        LONG                 OutputPhysicalType;
        LONG                 Depth;
    
        CRouting () {};
        ~CRouting () {};
    };
    
    int main()
    {
        typedef CGenericList<CRouting> CRoutingList;
    
        return 0;
    }
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I don't think it's a circular dependency problem if you've put this code in a .cpp file.
    I don't know of a generic way to detect circular dependencies, but you can try to tell the compiler to tell you what headers it includes. Then look at something suspicious regarding the files where you get the errors (the file which uses the type it can't find and the file which declares said type).
    #pragma once does not fix circular dependencies. It's mean to prevent multiple declaration errors and nothing else.

    There may be something in the header (e.g. conditional macros), which you could check, though.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Thanks Elysia!

    1. OK, this program compiles without error in MSVC but I get the error above mentioned in CodeBlocks.

    What can be the reason?

    2. I checked in MSVC the option '/showincludes' but I dont see the .h files included in the output window.

    3. Actually I checked Streams.h and it calls several *.h files so it still could be a circular dependancy problem.
    The question is what MSVC does that CodeBlocks doesn't that makes it compile in MSVC?
    Last edited by Ducky; 12-26-2014 at 08:20 AM.
    Using Windows 10 with Code Blocks and MingW.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    My guess it that you're not using the msvc compiler with code blocks. Anything non-microsoft has problems parsing the windows headers at times.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    These are my MSVC executable paths:

    $(VC_ExecutablePath_x86)
    $(WindowsSDK_ExecutablePath)
    $(VS_ExecutablePath)
    $(MSBuild_ExecutablePath)
    $(SystemRoot)\SysWow64


    This is my CodeBlocks executable path:
    C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC

    How to verify if VC_ExecutablePath_x86 is the same as the CodeBlocks path?
    Last edited by Ducky; 12-26-2014 at 10:01 AM.
    Using Windows 10 with Code Blocks and MingW.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    OK I found VC_ExecutablePath_x86 and it's the same as the CodeBlocks path. C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC

    So what else could it be?
    Using Windows 10 with Code Blocks and MingW.

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    It would help if you provided a small but complete sample of code that exhibited your problem. And information about the error message ..... such as what line of code in what file is causing it.

    I suspect, however, that the problem is what Elysia mentioned in post #4, which you seem to have ignored or skipped over.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Read and follow this CB FAQ
    FAQ-Compiling (errors) - CodeBlocks

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Quote Originally Posted by grumpy View Post
    It would help if you provided a small but complete sample of code that exhibited your problem. And information about the error message ..... such as what line of code in what file is causing it.
    It's all there in the first post: full code and error.

    It compiles in MSVC but not in CodeBlocks with the same compiler.

    I suspect, however, that the problem is what Elysia mentioned in post #4, which you seem to have ignored or skipped over.
    I answered Elysia in my 5th and 6th post.
    Using Windows 10 with Code Blocks and MingW.

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Ducky View Post
    It's all there in the first post: full code and error.
    The compiler diagnostics will also include information you have not provided - including name of the file (which may be either your source file or an #include'd header) and the line number. You provided no such information.

    You may be using the same compiler, but you also need to check if you are using the same compiler configuration. Code::Blocks will not necessarily invoke a compiler with the same settings (environment variables, etc) that Visual Studio would. That depends on how the settings are saved (e.g. different config files for different IDEs).

    Also, inability to find a class definition does not usually indicate circular dependencies. It usually means a relevant header file is not being #include'd (directly by your source file, or indirectly by headers #include'd by your source file). If you have circular dependencies (e.g. header A includes header B includes header A) a more common symptom is something with multiple definitions.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  11. #11
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Thank you Grumpy, I'll look into these things.

    What are the configuration files?

    Isnt it enough if I configure the search paths for the includes and library files? I mean the rest of my programs are compiling.

    What else needed?
    Last edited by Ducky; 12-27-2014 at 04:17 AM.
    Using Windows 10 with Code Blocks and MingW.

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    grumpy implies that the settings which Visual Studio uses and Code::Blocks when invoking the compiler may be different. You can find these in the compiler options of the IDE. Make sure they match (especially #defines).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    I copied the command line switches as it is in MSVC to Code::Blocks but I still get the same error.
    Using Windows 10 with Code Blocks and MingW.

  14. #14
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Thanks stahta, I went through it but I found nothing new.
    Last edited by Ducky; 12-27-2014 at 06:04 AM.
    Using Windows 10 with Code Blocks and MingW.

  15. #15
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Quote Originally Posted by grumpy View Post
    The compiler diagnostics will also include information you have not provided - including name of the file (which may be either your source file or an #include'd header) and the line number. You provided no such information.
    Code:
    test.cpp|25|error C2143: syntax error : missing ';' before '<'|
    test.cpp|25|error C4430: missing type specifier - int assumed. Note: C++ does not support default-int|
    ||=== Build finished: 2 errors, 0 warnings ===|
    Using Windows 10 with Code Blocks and MingW.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Circular Dependency A Dead End?
    By Waleed Mujeeb in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2012, 09:41 AM
  2. Circular main <- main.o dependency dropped.
    By Queatrix in forum C++ Programming
    Replies: 4
    Last Post: 10-21-2005, 02:32 PM
  3. Headers circular referencing problem
    By Malefaust in forum C Programming
    Replies: 5
    Last Post: 09-10-2005, 04:01 PM
  4. Replies: 3
    Last Post: 08-31-2005, 12:41 PM
  5. Circular dependency / Compile Error
    By jester in forum C++ Programming
    Replies: 4
    Last Post: 05-23-2003, 11:17 PM