CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2005
    Posts
    1,828

    error template with C linkage

    I am using G++ Compiler in LINUX. Why does this section of code causes this error template with C linkage?

    Code:
    template <class T>
    class CObjectCreator : public CCacheObjectCreator
    {
        T* CreateCacheObject(LPCSTR pszKey, LPCSTR pszExtra) { return new T(pszKey, pszExtra); }
    };
    Code:
    template <class T>
    class CAllocator : public CCacheAllocator
    {
    public:
        CAllocator(CCache* pCache, LPCSTR pszKey, LPCSTR pszExtra, DWORD dwExpirySecs, T*& pObject) : CCacheAllocator(pCache, pszKey, pszExtra, dwExpirySecs, new CObjectCreator<T>(), (CCacheObject *&)pObject) {}
    };

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    Re: error template with C linkage

    Any reason why that code would be within an extern "C" {} brackets?
    I would look for that first.

    gg

  3. #3
    Join Date
    Apr 2005
    Posts
    1,828

    Re: error template with C linkage

    This is an existing source code passed by 3rd party.

    Now this file that I am using has headers declared like this

    Code:
    #include "HttpHeaders.h"
    #include "List.h"
    #include "CriticalSection.h"
    #include <map>
    And once I open HttpHeaders.h...

    Code:
    extern "C"
    {
    #include "httpd.h"
    #include "http_config.h"
    #include "http_core.h"
    #include "http_log.h"
    #include "http_main.h"
    #include "http_protocol.h"
    #include "http_request.h"
    #include "util_script.h"
    #include "http_connection.h"
    #include "apr_strings.h"
    #include "apr_env.h"
    #include "apr_atomic.h"
    #include "ap_regex.h"
    #if !defined(_WINDOWS_)
    #include <unistd.h>
    #include <ctype.h>
    #endif
    }
    Is it this red extern C block creating the problem? I tried removing it but the problem still persists

  4. #4
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: error template with C linkage

    It could be that this header causes the error.

    Normally you define such headers like

    Code:
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    
    #include "httpd.h"
    #include "http_config.h"
    #include "http_core.h"
    #include "http_log.h"
    #include "http_main.h"
    #include "http_protocol.h"
    #include "http_request.h"
    #include "util_script.h"
    #include "http_connection.h"
    #include "apr_strings.h"
    #include "apr_env.h"
    #include "apr_atomic.h"
    #include "ap_regex.h"
    #if !defined(_WINDOWS_)
    #include <unistd.h>
    #include <ctype.h>
    #endif
    #ifdef __cplusplus
    }
    #endif
    That way you can use the header both from C and C++ sources.

  5. #5
    Join Date
    Nov 2003
    Posts
    1,902

    Re: error template with C linkage

    All the Apache headers already handle extern "C" {} themselves, so you can remove the unnecessary extern "C" block in HttpHeaders.h.

    Look in the other non-Apache headers as well for unnecessary blocks - and for any extern "C" lines without the braces.

    Also make sure your template code isn't being compiled as C code, by including it from a file with a ".c" extension.
    http://gcc.gnu.org/onlinedocs/gcc/Ov...verall-Options

    gg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured