Thread: CoInitialize() recognized but undefined

  1. #1
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591

    CoInitialize() recognized but undefined

    I need to call the function CoInitialize() to allow my listview to display background images, so I read the documentation and it sounded like a pretty straightforward function call: "CoInitialize(NULL)"... except I keep getting this error when compiling:
    .objs\app.o:hldj.c .text+0x7f9): undefined reference to `CoInitialize@4'
    .objs\app.o:app.c .text+0x1538): undefined reference to `CoUninitialize@0'
    At first I thought the error resulted from the compiler not having the function included, but that was not the case as when I tested CoInitialize() and CoInitialize(NULL, 0), the compiler was able to recognize that I was passing too few/too many arguments to the function. Also, I tried both CoInitializeEx and OleInitialize instead, but both gave the same errors.
    I'm not sure whats going on here, how can, on the one hand my compiler recognize the function by knowing its argument structure, but yet on the other hand tell me the function is an undefined reference. If its an undefined reference, where's it getting the information about its arguments from?
    I'm not sure if this is a compiler problem or if its just a simple oversight in code by myself, but just in case, here's the specs:
    C code compiled by GCC mingw32 in CodeBlocks RC2.
    Thanks for any insight you can provide me.
    Last edited by @nthony; 08-04-2006 at 05:35 PM.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You need to link with an import library. The import library tells your compiler where to find the function. You can find the proper import library at the bottom of the MSDN documentation page for each function. For CoInitialize, it is ole32.lib. Your compiler may use a slightly different naming scheme where it would be called libole32.a. To link with a library using CodeBlocks, go to Build Options and then the Linker tab, as shown in step 5 on this page.

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    thanks again anonytmouse!
    Just out of curiousity, how was the compiler getting information about the function's argument list? was it from some declaration in one of the windows headers?

    Also, does anyone know what is considered to be a valid "URL" in this context:
    LVBKIF_SOURCE_URL
    The pszImage member contains the URL of the background image.
    Thanks.
    Last edited by @nthony; 08-04-2006 at 07:08 PM.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> Just out of curiousity, how was the compiler getting information about the function's argument list? was it from some declaration in one of the windows headers? <<

    Yes. Function prototypes are included in header files. The import library basically just tells the linker where the function is located (which DLL).

    >> Also, does anyone know what is considered to be a valid "URL" in this context: <<

    Just a normal file path is fine. There is a sample of using a list-view as an image box.

  5. #5
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    oh wow that's exactly what I needed, thanks so much again!
    .. so when will I be getting the bill in the mail?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  3. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  4. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM