由于未定义的引用,Mingw64没有链接

时间:2015-10-04 19:25:03

标签: c++ linker mingw-w64 comdlg32

我开始学习mingw64并试图使用netbeans 8.0.1来编译这个cpp文件 我需要看到的是打印窗口和打印文本的对话框" Hola mundo"。

#include <stdio.h>
#include <windows.h>
#include <string.h>

void printer(const char text[]) {
    //Bring up a dialog to choose the printer
    PRINTDLG pd = {0};
    pd.lStructSize = sizeof(pd);
    pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC;
    pd.nCopies = 1;

    //show the printer dialog
    PrintDlg(&pd);

    //Zero and then initialize the members of a DOCINFO structure
    DOCINFO di = {0};
    di.cbSize = sizeof(DOCINFO);
    di.lpszDocName = "Scribble Printout";
    di.lpszOutput = (LPTSTR) NULL;
    di.lpszDatatype = (LPTSTR) NULL;
    di.fwType = 0;

    //Begin a print job by calling the StartDoc function
    StartDoc(pd.hDC, &di);

    //send some text
    TextOut(pd.hDC, 800, 800, text, strlen(text));
    //lets close the printer
    //inform the driver that the page is finished
    EndPage(pd.hDC);

    //inform the driver the the document has ended
    EndDoc(pd.hDC);
}
/*
 * 
 */
int main()
{
    printer("Hola mundo");
    return 0;
}

但是当我尝试构建链接器时会产生如下错误:

"/C/programas/msys32/usr/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory '/c/Users/mplescano/Documents/NetBeansProjects/CppApplication_2'
rm -f -r build/Debug
rm -f dist/Debug/MinGW-Windows/cppapplication_2.exe
make[1]: Leaving directory '/c/Users/mplescano/Documents/NetBeansProjects/CppApplication_2'

CLEAN SUCCESSFUL (total time: 2s)
"/C/programas/msys32/usr/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/c/Users/mplescano/Documents/NetBeansProjects/CppApplication_2'
"/C/programas/msys32/usr/bin/make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cppapplication_2.exe
make[2]: Entering directory '/c/Users/mplescano/Documents/NetBeansProjects/CppApplication_2'
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/main.o.d"
g++    -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.cpp
mkdir -p dist/Debug/MinGW-Windows
g++     -o dist/Debug/MinGW-Windows/cppapplication_2 build/Debug/MinGW-Windows/main.o  -v
Using built-in specs.
COLLECT_GCC=C:\programas\mingw-w64\i686-5.2.0-posix-dwarf-rt_v4-rev0\mingw32\bin\g++.exe
COLLECT_LTO_WRAPPER=C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../libexec/gcc/i686-w64-mingw32/5.2.0/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../../../src/gcc-5.2.0/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/c/mingw520/i686-520-posix-dwarf-rt_v4-rev0/mingw32 --with-gxx-include-dir=/mingw32/i686-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-sjlj-exceptions --with-dwarf2 --disable-isl-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/c/mingw520/prerequisites/i686-w64-mingw32-static --with-mpfr=/c/mingw520/prerequisites/i686-w64-mingw32-static --with-mpc=/c/mingw520/prerequisites/i686-w64-mingw32-static --with-isl=/c/mingw520/prerequisites/i686-w64-mingw32-static --with-pkgversion='i686-posix-dwarf-rev0, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw520/i686-520-posix-dwarf-rt_v4-rev0/mingw32/opt/include -I/c/mingw520/prerequisites/i686-zlib-static/include -I/c/mingw520/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/c/mingw520/i686-520-posix-dwarf-rt_v4-rev0/mingw32/opt/include -I/c/mingw520/prerequisites/i686-zlib-static/include -I/c/mingw520/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw520/i686-520-posix-dwarf-rt_v4-rev0/mingw32/opt/lib -L/c/mingw520/prerequisites/i686-zlib-static/lib -L/c/mingw520/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware'
Thread model: posix
gcc version 5.2.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 
COMPILER_PATH=C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../libexec/gcc/i686-w64-mingw32/5.2.0/;C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../libexec/gcc/;C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/bin/
LIBRARY_PATH=C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/;C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/;C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/lib/../lib/;C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../lib/;C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/lib/;C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../
COLLECT_GCC_OPTIONS='-o' 'dist/Debug/MinGW-Windows/cppapplication_2.exe' '-v' '-shared-libgcc' '-mtune=generic' '-march=i686'
 C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../libexec/gcc/i686-w64-mingw32/5.2.0/collect2.exe -plugin C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../libexec/gcc/i686-w64-mingw32/5.2.0/liblto_plugin-0.dll -plugin-opt=C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../libexec/gcc/i686-w64-mingw32/5.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\MPLESC~1\AppData\Local\Temp\ccd4OtP8.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-liconv -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt --sysroot=C:/mingw520/i686-520-posix-dwarf-rt_v4-rev0/mingw32 -m i386pe -Bdynamic -u ___register_frame_info -u ___deregister_frame_info -o dist/Debug/MinGW-Windows/cppapplication_2.exe C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/lib/../lib/crt2.o C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/crtbegin.o -LC:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0 -LC:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc -LC:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/lib/../lib -LC:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../lib -LC:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../../../i686-w64-mingw32/lib -LC:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/../../.. build/Debug/MinGW-Windows/main.o -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -liconv -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt C:/programas/mingw-w64/i686-5.2.0-posix-dwarf-rt_v4-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.2.0/crtend.o
build/Debug/MinGW-Windows/main.o: In function `Z7printerPKc':
C:\Users\mplescano\Documents\NetBeansProjects\CppApplication_2/main.cpp:19: undefined reference to `_imp__PrintDlgA@4'
C:\Users\mplescano\Documents\NetBeansProjects\CppApplication_2/main.cpp:30: undefined reference to `_imp__StartDocA@8'
C:\Users\mplescano\Documents\NetBeansProjects\CppApplication_2/main.cpp:33: undefined reference to `_imp__TextOutA@20'
C:\Users\mplescano\Documents\NetBeansProjects\CppApplication_2/main.cpp:36: undefined reference to `_imp__EndPage@4'
C:\Users\mplescano\Documents\NetBeansProjects\CppApplication_2/main.cpp:39: undefined reference to `_imp__EndDoc@4'
collect2.exe: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/MinGW-Windows/cppapplication_2.exe' failed
make[2]: *** [dist/Debug/MinGW-Windows/cppapplication_2.exe] Error 1
make[2]: Leaving directory '/c/Users/mplescano/Documents/NetBeansProjects/CppApplication_2'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/c/Users/mplescano/Documents/NetBeansProjects/CppApplication_2'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 11s)


你能帮助我吗??感谢。

0 个答案:

没有答案