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. Call C functions from VC++

Call C functions from VC++

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionhelpannouncement
13 Posts 4 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.
  • P phil o

    Maybe that can help: SO: Compile C files in C++ project which do not use precompiled header?[^] Top-most answer presents some simple workarounds. If there are a lot of .c files in your project, disabling precompiled-headers solution-wide seems appropriate.

    enum HumanBool { Yes, No, Maybe, Perhaps, Probably, ProbablyNot, MostLikely, MostUnlikely, HellYes, HellNo, Wtf }

    _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #3

    I saw that post, I have tried all that solutions, I still have the same error ...

    P 1 Reply Last reply
    0
    • _ _Flaviu

      I saw that post, I have tried all that solutions, I still have the same error ...

      P Offline
      P Offline
      phil o
      wrote on last edited by
      #4

      Strange. Maybe there are some leftovers from previous compilation sessions. Did you try to clean the solution and rebuild it completely? Does the error appear for all .c source files, or only for specific one(s)?

      enum HumanBool { Yes, No, Maybe, Perhaps, Probably, ProbablyNot, MostLikely, MostUnlikely, HellYes, HellNo, Wtf }

      1 Reply Last reply
      0
      • _ _Flaviu

        Is there any method to call C code from VC++/MFC project ? I need to call some functions from a C project (pretty big project). If I include some files from that C project, I get some error:

        precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)

        moreover, I get a lot of unrecongnized types ... to modify types and functions in C project is huge work ... how can I overcome this ? Maybe you have been in the same situaton like me ...

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #5

        It may possibly depend on how you are connecting the two. In general calling C functions from MFC/C++ presents no problems and works out of the box. Maybe if you showed some of the headers that you are including and the associated error messages we may be able to figure something out.

        _ 1 Reply Last reply
        0
        • L Lost User

          It may possibly depend on how you are connecting the two. In general calling C functions from MFC/C++ presents no problems and works out of the box. Maybe if you showed some of the headers that you are including and the associated error messages we may be able to figure something out.

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #6

          I have included C header and fix some errors, but I met another error:

          MyDoc.obj : error LNK2019: unresolved external symbol _function1 referenced in function "public: int __thiscall CMyDoc::SomeMethod
          MyDoc.obj : error LNK2019: unresolved external symbol _function2 referenced in function "public: int __thiscall CMyDoc::SomeMEthod

          so, if I included xxx.c file, I got tones of errors ... if I added that file to my project, happen nothing, I mean I got the same errors ... what could be the next step ?

          L 1 Reply Last reply
          0
          • _ _Flaviu

            I have included C header and fix some errors, but I met another error:

            MyDoc.obj : error LNK2019: unresolved external symbol _function1 referenced in function "public: int __thiscall CMyDoc::SomeMethod
            MyDoc.obj : error LNK2019: unresolved external symbol _function2 referenced in function "public: int __thiscall CMyDoc::SomeMEthod

            so, if I included xxx.c file, I got tones of errors ... if I added that file to my project, happen nothing, I mean I got the same errors ... what could be the next step ?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #7

            The linker errors are telling you that some file or object is missing from the build. Check where function1 and function2 are defined, and make sure that the file that contains them is included in your project..

            _ 1 Reply Last reply
            0
            • L Lost User

              The linker errors are telling you that some file or object is missing from the build. Check where function1 and function2 are defined, and make sure that the file that contains them is included in your project..

              _ Offline
              _ Offline
              _Flaviu
              wrote on last edited by
              #8

              Yes, I included, but I got the first error: precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa) even if I did that settings in my VC++ app, I still have this error ...

              L D 2 Replies Last reply
              0
              • _ _Flaviu

                Yes, I included, but I got the first error: precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa) even if I did that settings in my VC++ app, I still have this error ...

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #9

                You are using a previously built precompiled header so you need to force a complete rebuild of your project to ensure it is recreated with the current compiler and header files. Unfortunately most of this is guesswork as we cannot see the structure of your project(s). As I said earlier, calling C functions from C++ always works if you have the correct header and source/object files included.

                1 Reply Last reply
                0
                • _ _Flaviu

                  Yes, I included, but I got the first error: precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa) even if I did that settings in my VC++ app, I still have this error ...

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #10

                  _Flaviu wrote:

                  ...even if I did that settings in my VC++ app

                  What settings?

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                  _ 1 Reply Last reply
                  0
                  • D David Crow

                    _Flaviu wrote:

                    ...even if I did that settings in my VC++ app

                    What settings?

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                    _ Offline
                    _ Offline
                    _Flaviu
                    wrote on last edited by
                    #11

                    This one: Compile C files in C++ project which do not use precompiled header? - Stack Overflow[^]

                    L 2 Replies Last reply
                    0
                    • _ _Flaviu

                      This one: Compile C files in C++ project which do not use precompiled header? - Stack Overflow[^]

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #12

                      That is irrelevant. You need to show us the actual details from your project. Whatever you are doing, or not doing, to cause these errors, we cannot help you without seeing some proper details.

                      1 Reply Last reply
                      0
                      • _ _Flaviu

                        This one: Compile C files in C++ project which do not use precompiled header? - Stack Overflow[^]

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #13

                        It just occurred to me that you are probably suffering from C++ name mangling. You need to add the following lines to the header files of your .c code:

                        #ifdef __cplusplus // these lines at the beginning of the file before your definitions
                        extern "C" {
                        #endif

                        #ifdef __cplusplus // these lines at the end of the file after your definitions
                        }
                        #endif

                        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