Shared Library

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • InNeedOfHelp
    New Member
    • Jun 2006
    • 27

    Shared Library

    Hi,

    I am having problems with a shared library I have created to use in my MSVC project.

    The main function in the library looks like this;

    extern void mlfMain();

    When I try to call this function from within the VC project I get an error saying 'mlfMain()' : undeclared identifier.

    I call it simply by the following;

    mlfMain();

    I have include the shared library (meshlib.h) as;

    #include "C:\...\...\mes hlib.h" at the top of my file.

    Can anyone point me in the right direction? Is it to do with my project settings? or something, thanks in advance.
  • InNeedOfHelp
    New Member
    • Jun 2006
    • 27

    #2
    Anyone?

    I'm sure its probably really simple but I have never done this before and I'm really struggling! Any pointers at all?

    Thanks

    Comment

    • InNeedOfHelp
      New Member
      • Jun 2006
      • 27

      #3
      Sorry,
      Perhaps I should have mentioned that I created the library via the Matlab compiler by converting some matlab files to C files!

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        What sort of library is it? How is it linked with your program?

        Comment

        • InNeedOfHelp
          New Member
          • Jun 2006
          • 27

          #5
          Originally posted by Banfa
          What sort of library is it? How is it linked with your program?
          From the Matlab compiler I got a number of files (.dll and .lib amongst others) I am not sure what type of library it is (is there anyway to tell, I guess I should already know?) To link it to the program I have included the file path (of the .lib file) in the 'Object/library modules:' option in the link section of the project settings dialog box. However this was really no more than an act of blind desparation!

          I haven't had any experience of changing project settings, linking external files - any help would be greatly appreciated. Cheers Banfa

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            OK a library will have at least 2 files

            a header, <library>.h which contains the function and datatype declarations to be included into you code. There is not reason why a library should only have 1 header but that is the normal way to do it.

            a library file, <library.lib> that contains the object code of the library, this should be included in the link stage of your program.

            it may also have a <library>.dll file if the library is a dynamic link library. The dll file is not required while building the executable but is required to run it.



            Things to do

            1. Include the library in the link, including it in the 'Object/library modules:' setting sounds like the right thing to do.

            2. Make sure the header contains an mlfMain, if it doesn't you weren't intended to call it even if it exsits in the library.

            Comment

            • InNeedOfHelp
              New Member
              • Jun 2006
              • 27

              #7
              The files I that were created from the Matlab compiler were as follows;
              <library>.expor ts, <library>.c, <library>.ctf , <library>.dll , <library>.exp , <library>.lib , <library>_mcc_c omponent_data.c and <library>.h

              not sure if the above is important but I include it just incase!


              I have included the <library>.lib file in the 'Object/library modules:' option (is it the .lib file that is to be included?). I checked the header file and mlfMain is declared as follows;

              extern void mlfMain();


              the header file has been included in the program as;

              #include "C:\..\<library >.h"


              however when I compile the program I get the error message;

              C:\..\meshDoc.c pp(42) : error C2065: 'mlfMain' : undeclared identifier


              It is not only the mlfMain function that gives this error, there are other functions (<library>Initi alize(), <library>Termin ate() - which the Matlab website says are neccesary) that give the same error.

              I have no idea what the problem is, again as always Banfa your help is really appreciated.
              Thank you.

              Comment

              • Banfa
                Recognized Expert Expert
                • Feb 2006
                • 9067

                #8
                A quick look at the MatLab website (just go to the website and search on mlfMain) sujjests that you should also have a c file (or files) that contain you matLab defined functions including mlfMain, presumably in your case this means "<library>_mcc_ component_data. c". This/these files should be compiled and linked into your program as well.

                Additionally it means that there should be a C file containing the function mlfMain somewhere in your MatLab generated C source code so you can search that source code for that function.

                Comment

                Working...