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. using static library for C code in Visual studio 2005

using static library for C code in Visual studio 2005

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studioquestion
15 Posts 5 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.
  • S sunny_vc

    Hi, I am working on a simple win32 console based application in C in visual studio2005. My application uses a third party static library. So I have included the path of the library and the library in additional dependencies for linker input. My code compiles and works fine if I compile this code as C++ code. But If I want to compile this as C code, for the same library functions, I am getting unresolved external symbols. Can any one please let me know, if I have to change anything for this library to compile as C code.?

    Regards, Sunil Kumar

    P Offline
    P Offline
    pasztorpisti
    wrote on last edited by
    #2

    Its possible to do that but depending on your unresolved external symbols you might have to use a thin layer of C++ between your C code and the C++ library.

    1 Reply Last reply
    0
    • S sunny_vc

      Hi, I am working on a simple win32 console based application in C in visual studio2005. My application uses a third party static library. So I have included the path of the library and the library in additional dependencies for linker input. My code compiles and works fine if I compile this code as C++ code. But If I want to compile this as C code, for the same library functions, I am getting unresolved external symbols. Can any one please let me know, if I have to change anything for this library to compile as C code.?

      Regards, Sunil Kumar

      M Offline
      M Offline
      Malli_S
      wrote on last edited by
      #3

      The library is compiled as C++ code, due which the function names exported by the library are mangled. When you compile your code as C code, the name mangling is disabled, due to which the linker looks for un-mangled version of the function calls you're using from the third party library. And hence the unresolved external symbol errors are shown. The way out for this is use dynamic loading of that DLL.

      [Delegates]      [Virtual Desktop]      [Tray Me !]
      -Malli...! :rose:****

      S C J 3 Replies Last reply
      0
      • M Malli_S

        The library is compiled as C++ code, due which the function names exported by the library are mangled. When you compile your code as C code, the name mangling is disabled, due to which the linker looks for un-mangled version of the function calls you're using from the third party library. And hence the unresolved external symbol errors are shown. The way out for this is use dynamic loading of that DLL.

        [Delegates]      [Virtual Desktop]      [Tray Me !]
        -Malli...! :rose:****

        S Offline
        S Offline
        sunny_vc
        wrote on last edited by
        #4

        Hi Malli, thanks for the reply. So in that case,by using dynamic loading of library using LoadLibrary, we can avoid this even the library is compiled as C++.?

        Regards, Sunil Kumar

        M 1 Reply Last reply
        0
        • M Malli_S

          The library is compiled as C++ code, due which the function names exported by the library are mangled. When you compile your code as C code, the name mangling is disabled, due to which the linker looks for un-mangled version of the function calls you're using from the third party library. And hence the unresolved external symbol errors are shown. The way out for this is use dynamic loading of that DLL.

          [Delegates]      [Virtual Desktop]      [Tray Me !]
          -Malli...! :rose:****

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #5

          Malli_S wrote:

          The way out for this is use dynamic loading of that DLL.

          DLL?

          image processing toolkits | batch image processing

          M 1 Reply Last reply
          0
          • S sunny_vc

            Hi Malli, thanks for the reply. So in that case,by using dynamic loading of library using LoadLibrary, we can avoid this even the library is compiled as C++.?

            Regards, Sunil Kumar

            M Offline
            M Offline
            Malli_S
            wrote on last edited by
            #6

            Yes, provided that you have function prototype with you and the function pointer defined for the function you are calling.

            [Delegates]      [Virtual Desktop]      [Tray Me !]
            -Malli...! :rose:****

            1 Reply Last reply
            0
            • C Chris Losinger

              Malli_S wrote:

              The way out for this is use dynamic loading of that DLL.

              DLL?

              image processing toolkits | batch image processing

              M Offline
              M Offline
              Malli_S
              wrote on last edited by
              #7

              Chris Losinger wrote:

              DLL?

              I meant to say using LoadLibrary().

              [Delegates]      [Virtual Desktop]      [Tray Me !]
              -Malli...! :rose:****

              C 1 Reply Last reply
              0
              • M Malli_S

                Chris Losinger wrote:

                DLL?

                I meant to say using LoadLibrary().

                [Delegates]      [Virtual Desktop]      [Tray Me !]
                -Malli...! :rose:****

                C Offline
                C Offline
                Chris Losinger
                wrote on last edited by
                #8

                but the post says nothing about a DLL. it says "static library".

                image processing toolkits | batch image processing

                M 1 Reply Last reply
                0
                • C Chris Losinger

                  but the post says nothing about a DLL. it says "static library".

                  image processing toolkits | batch image processing

                  M Offline
                  M Offline
                  Malli_S
                  wrote on last edited by
                  #9

                  Hmm. I should have mentioned about the DLLs. I was trying to focus on dynamic linking, rather than static linking. My mistake. I missed that.

                  [Delegates]      [Virtual Desktop]      [Tray Me !]
                  -Malli...! :rose:****

                  S 1 Reply Last reply
                  0
                  • M Malli_S

                    Hmm. I should have mentioned about the DLLs. I was trying to focus on dynamic linking, rather than static linking. My mistake. I missed that.

                    [Delegates]      [Virtual Desktop]      [Tray Me !]
                    -Malli...! :rose:****

                    S Offline
                    S Offline
                    sunny_vc
                    wrote on last edited by
                    #10

                    Hi, the good thing is that I have both static and dynamic libraries. But I wanted to use only static, so that I can distribute only an exe. But anyway, now I will have to use the dynamic library. Thanks for the help.

                    Regards, Sunil Kumar

                    1 Reply Last reply
                    0
                    • M Malli_S

                      The library is compiled as C++ code, due which the function names exported by the library are mangled. When you compile your code as C code, the name mangling is disabled, due to which the linker looks for un-mangled version of the function calls you're using from the third party library. And hence the unresolved external symbol errors are shown. The way out for this is use dynamic loading of that DLL.

                      [Delegates]      [Virtual Desktop]      [Tray Me !]
                      -Malli...! :rose:****

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #11

                      Malli_S wrote:

                      The way out for this is use dynamic loading of that DLL.

                      Which is rather convoluted given that one can use extern C.

                      1 Reply Last reply
                      0
                      • S sunny_vc

                        Hi, I am working on a simple win32 console based application in C in visual studio2005. My application uses a third party static library. So I have included the path of the library and the library in additional dependencies for linker input. My code compiles and works fine if I compile this code as C++ code. But If I want to compile this as C code, for the same library functions, I am getting unresolved external symbols. Can any one please let me know, if I have to change anything for this library to compile as C code.?

                        Regards, Sunil Kumar

                        J Offline
                        J Offline
                        jschell
                        wrote on last edited by
                        #12

                        If it was me I would put a C function wrapper around it. And compile that at a library. Then your app uses the second library. The dynamic loader solution works but it means that you must deal with the name mangling yourself rather than letting the compiler do it. And if the C++ requires an C++ idioms, like creating a class, then doing thing via dynamic method calls is going to be difficult.

                        M 1 Reply Last reply
                        0
                        • J jschell

                          If it was me I would put a C function wrapper around it. And compile that at a library. Then your app uses the second library. The dynamic loader solution works but it means that you must deal with the name mangling yourself rather than letting the compiler do it. And if the C++ requires an C++ idioms, like creating a class, then doing thing via dynamic method calls is going to be difficult.

                          M Offline
                          M Offline
                          Malli_S
                          wrote on last edited by
                          #13

                          But it's a third party library. He might not have the source code for that.

                          [Delegates]      [Virtual Desktop]      [Tray Me !]
                          -Malli...! :rose:****

                          S J 2 Replies Last reply
                          0
                          • M Malli_S

                            But it's a third party library. He might not have the source code for that.

                            [Delegates]      [Virtual Desktop]      [Tray Me !]
                            -Malli...! :rose:****

                            S Offline
                            S Offline
                            sunny_vc
                            wrote on last edited by
                            #14

                            Hi, One more thing is,it compiles properly for C++ in debug mode. But in Release mode the same unresolved external errors, I am getting for the functions. I have mentioned the project properties in Release mode same as in Debug mode. But still it is unable to link to the functions in the library. Why this behavior.Does it mean, the library is compiled in debug mode? Regards, Sunil.

                            Regards, Sunil Kumar

                            1 Reply Last reply
                            0
                            • M Malli_S

                              But it's a third party library. He might not have the source code for that.

                              [Delegates]      [Virtual Desktop]      [Tray Me !]
                              -Malli...! :rose:****

                              J Offline
                              J Offline
                              jschell
                              wrote on last edited by
                              #15

                              Malli_S wrote:

                              But it's a third party library. He might not have the source code for that.

                              That has nothing to do with what I said.

                              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