Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Linking C libraries to C++?

Linking C libraries to C++?

Scheduled Pinned Locked Moved C / C++ / MFC
c++toolshelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    balaclavabob
    wrote on last edited by
    #1

    Pre-compiled a C library using msvc 6, blah.lib In a new C++ project, include header and library location in Tools->Options->Directories, included header in the C++ file and include library in the Settings->Link tab I get a linker error stating: main.obj : error LNK2001: unresolved external symbol "int __cdecl hInitialise(int,struct HWND__ *,struct HDC__ *,unsigned int)" (?hInitialise@@YAHHPAUHWND__@@PAUHDC__@@I@Z) I was not able to recompile the library into C++, cause of header problems....

    C 1 Reply Last reply
    0
    • B balaclavabob

      Pre-compiled a C library using msvc 6, blah.lib In a new C++ project, include header and library location in Tools->Options->Directories, included header in the C++ file and include library in the Settings->Link tab I get a linker error stating: main.obj : error LNK2001: unresolved external symbol "int __cdecl hInitialise(int,struct HWND__ *,struct HDC__ *,unsigned int)" (?hInitialise@@YAHHPAUHWND__@@PAUHDC__@@I@Z) I was not able to recompile the library into C++, cause of header problems....

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      This smells like a name mangling issue. Try to wrap the header file that contains your function declarations with

      extern "C"
      {
      ...
      ... all of your functions
      ...
      }

      and then rebuild your library and then rebuild your app. Chris Meech I am Canadian. [heard in a local bar] Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden] Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]

      B 1 Reply Last reply
      0
      • C Chris Meech

        This smells like a name mangling issue. Try to wrap the header file that contains your function declarations with

        extern "C"
        {
        ...
        ... all of your functions
        ...
        }

        and then rebuild your library and then rebuild your app. Chris Meech I am Canadian. [heard in a local bar] Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden] Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]

        B Offline
        B Offline
        balaclavabob
        wrote on last edited by
        #3

        Thanks for the suggestion Chris, it didn't work. The cpp files generated a host of other errors. I googled extern "C" to see how else I could use it. I tried putting the function declaration at the top of my file and used: extern "C" int hInitialise(int count, HWND window, HDC screen, unsigned int flags); Got a compile error: main.cpp(13) : error C2732: linkage specification contradicts earlier specification for 'hInitialise' But I copied it straight from the header....:confused:

        M 1 Reply Last reply
        0
        • B balaclavabob

          Thanks for the suggestion Chris, it didn't work. The cpp files generated a host of other errors. I googled extern "C" to see how else I could use it. I tried putting the function declaration at the top of my file and used: extern "C" int hInitialise(int count, HWND window, HDC screen, unsigned int flags); Got a compile error: main.cpp(13) : error C2732: linkage specification contradicts earlier specification for 'hInitialise' But I copied it straight from the header....:confused:

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          You don't have to copy anything. In your C++ code do this:

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

          --Mike-- LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ | You Are Dumb Magnae clunes mihi placent, nec possum de hac re mentiri.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups