Menu

Linker error on using "CreateCompa...

2010-03-03
2012-09-26
  • Dmitry Titov

    Dmitry Titov - 2010-03-03

    I have created the project. The project type is "Win32 DLL". There is the
    following string in my project:
    HDC hCDC = CreateCompatibleDC(hdc);
    I see following error after compiling:
    undefined reference to `CreateCompatibleDC@4'
    But if i will create the project with type "Win32 GUI" and put this string
    into it it will compiles without any errors. Why?

    How can I compile my project with type "Win32 DLL"?
    I am sorry if I have put my question to the wrong section.

     
  • DARC

    DARC - 2010-03-04

    I don't know much about windows or dll's. As for the error, you must define
    the func CreateCompatibleDC() in your code or link with a library that defines
    it. It may work with Win32 GUI because it loads with default files or paths to
    those files. One of the default files has the definition of
    CreateCompatileDC().

     
  • Dmitry Titov

    Dmitry Titov - 2010-03-04

    How I can see, what files get linked automatically to a project?

     
  • DARC

    DARC - 2010-03-05

    A windows project is going to have a " #include <windows.h> " in your main
    source file.
    Inside of " windows.h " there will be different " #include " statements. Any
    header file (.h) and or source file (.cpp) you add can include files too.
    Basicly they will all be linked in your final program.
    Your problem is that one of your header files(.h), source files(.cpp), or
    libray files (lib*.a) does not have a definition for "CreateCompatibleDC()".
    You need to link with the right library and or source file if DLL's work like
    a special library built for windows applications.
    If this is your own function make sure you: 1 declare it; 2. define it;
    optional 3. declare and define it in same place; 4. add to your project (if a
    source file) or source file (if a header file).
    Happy Hunting

     
  • Dmitry Titov

    Dmitry Titov - 2010-03-05

    The function declaration “CreateCompatibleDC” is in a file “wingdi.h”. This
    file is connected to the project as follows: “Tools-> CompilerOption->
    Directories-> CInclude” the path “C:\Dev-Cpp\include \is specified”. Here
    there is a file “wingdi.h”. The function description “CreateCompatibleDC” in
    library “libgdi32.a”. This library is to the address “C:\Dev-Cpp\lib \”. It is
    the address it is specified in compiler customisations: “Tools->
    CompilerOption-> Directories-> Libraries”.
    Specified above customisation are identical to both projects, but for the type
    project “WIN32 DLL” the compiler produces an error. For the type project
    “WIN32 GUI” compilation passes successfully.
    In a directory with the type project “WIN32 DLL” I have copied a file
    “libgdi32.a”. Also has made following customisations: “Project->
    ProjectOptions-> Parameters-> Linker” has entered a filename “libgdi32.a”.
    Compilation has passed successfully.
    Why? After all the file “libgdi32.a” should be connected to the project
    without additional customisations?

     
  • DARC

    DARC - 2010-03-06

    Good job. How did you find the definition in that library??
    By the way the solution was
    "Project->ProjectOptions->Parameters->Linker\libgdi32.a". The library was in
    the search path (you stated) so the linker parameter was the answer.
    Libgdi32.a is somehow not default in DLL projects, but it is default in WIN
    gui project.
    I wonder if it would have worked if you had added the libgdi32.a as a project
    file, but had left out the linker parameter? You know just like adding source
    files to a library project. I haven't created no DLLs and only a few basic
    librarys from book examples. Anyways, good job and get back with how you found
    the definition in that library

     
  • Dmitry Titov

    Dmitry Titov - 2010-03-09

    I know "CreateCompatibleDC" is GDI function. The only library contains letters
    "gdi" at its name is libgdi32.a. I have connected this library and everything
    works.
    But i can't understand why this library must be connected especially?

     
  • Dmitry Titov

    Dmitry Titov - 2010-03-09

    There are also special utilities to view functions contained in dynamic or
    static libraries.

     
  • DARC

    DARC - 2010-03-10

    Have you used "C++filter.exe"? I cant seem to make it work. It echos back my
    parameter only. I resently got this old exacutable called "nm.exe" from the
    DJGPP suite of C++ . I had to make a batch program to filter out all the info
    it provides. "C++filter.exe" is newer, but it doesn't give any data at all.
    Does it store it to a file?? I have many library files from Quincy2002 suite,
    Dev-C++ suite, and recently the DJGPP suite but you cant open them to see what
    they contain. The header files usually look cryptic and look like they contain
    either C or weird macro constructs. I only use what the book I am currently
    reading dictates. That usually is a small hand full of headers and what ever
    default library the IDE is set up to compile with. Any help with learning more
    about all the headers and librarys is appreciated.
    Sorry about the last question you posted, I don't think I understand what your
    asking.

     
  • laxman varada

    laxman varada - 2010-08-16

    hi,
    As for the error, you must define the func CreateCompatibleDC() in your code
    or link with a library that defines it. It may work with Win32 GUI because it
    loads with default files or paths to those files. One of the default files has
    the definition of CreateCompatileDC().

    regards,
    phe9oxis,
    http://www.guidebuddha.com

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.