0

I'm using a library from github to help speed up building my program. I'm coding in C++, and have been having some linking issues.

For one .cpp, I kept getting the "undefined reference" error. I wrapped the header link:

extern "C" {
    #include "foo.h"
}

and the errors were resolved.

But now I have a bunch of "error: template with C linkage" errors in one of my other header files:

#ifndef _STRINGFWD_H
#define _STRINGFWD_H 1

#pragma GCC system_header

#include <bits/c++config.h>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

  template<typename _Alloc>
    class allocator;

/**
 *  @defgroup strings Strings
 *
 *  @{
*/

template<class _CharT>
struct char_traits;

 template<typename _CharT, typename _Traits = char_traits<_CharT>,
          typename _Alloc = allocator<_CharT> >
  class basic_string;

 template<> struct char_traits<char>;

 typedef basic_string<char>    string;   /// A string of @c char

#ifdef _GLIBCXX_USE_WCHAR_T
  template<> struct char_traits<wchar_t>;

  typedef basic_string<wchar_t> wstring;   /// A string of @c wchar_t
#endif

#if (defined(__GXX_EXPERIMENTAL_CXX0X__) \
     && defined(_GLIBCXX_USE_C99_STDINT_TR1))

  template<> struct char_traits<char16_t>;
  template<> struct char_traits<char32_t>;

  typedef basic_string<char16_t> u16string; /// A string of @c char16_t
  typedef basic_string<char32_t> u32string; /// A string of @c char32_t

#endif
   /** @}  */

_GLIBCXX_END_NAMESPACE_VERSION
} // namespace

#endif  // _STRINGFWD_H

I'm new to coding, so I'm not sure how to resolve these linking issues. Any help is greatly appreciated!

  • Because `foo.h` includes C++ centric header files. You need to fix `foo.h` as well. – Captain Obvlious Sep 21 '15 at 21:12
  • 1
    On second though `extern "C" {` probably isn't even required. What is `foo.h` exactly and what library are you trying to use? – Captain Obvlious Sep 21 '15 at 21:50
  • I'm building an application to integrate with twitter (letting a device tweet when a condition changes/is met), so `foo.h` is a source file from the library containing all the code to access the twitter client that I just have to provide values for. It has header links to ``, ``, ``, and the header file included above. The github source is "twitcurl". –  Sep 22 '15 at 14:19
  • Also, I just looked at the file above and its part of the GNU ISO C++ Library. So I have C and C++ stuff going on apparently? –  Sep 22 '15 at 14:25
  • This sounds like an [XY Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Your actual problem is the unresolved external symbols which is what you should be asking about. – Captain Obvlious Sep 22 '15 at 15:30
  • I did and was directed to [What is an undefined reference...](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix), and that's where I got using `extern "C"` to resolve the references. –  Sep 22 '15 at 15:44

0 Answers0