0.c++-显式打印、改变lib库加载顺序(/verbose:lib)

本文介绍了解决在使用Microsoft Visual Studio进行项目编译过程中遇到的MFC与CRT内存分配函数重复定义的问题。通过调整库文件的加载顺序,确保MFC库优先被加载,从而避免了内存分配和释放函数的多重定义错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天编译了下代码:提示以下错误,因为nafxcw.lib是MFC的,所以必须首先被编译

1>正在链接…
1>nafxcw.lib(afxmem.obj) : error LNK2005: “void * __cdecl operator new(unsigned int)” (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj) 中定义
测试下,在Link–>cmd中加入/verbose:lib,查看打印的顺序:

>正在搜索库
1>	正在搜索 D:\Program Files\Microsoft Visual Studio 9.0\VC\lib\DelayImp.lib:
1>	正在搜索 C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\uuid.lib:
1>	正在搜索 D:\Program Files\Microsoft Visual Studio 9.0\VC\lib\libcpmt.lib:
1>	正在搜索 .\Lib_MT\log4cplusS.lib:
1>	正在搜索 D:\Program Files\Microsoft Visual Studio 9.0\VC\lib\LIBCMT.lib:
1>	正在搜索 D:\Program Files\Microsoft Visual Studio 9.0\VC\lib\OLDNAMES.lib:
1>	正在搜索 D:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\lib\nafxcw.lib:
1>nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj) 中定义
1>nafxcw.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) 已经在 LIBCMT.lib(delete.obj) 中定义
1>nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) 已经在 LIBCMT.lib(new2.obj) 中定义
1>nafxcw.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) 已经在 LIBCMT.lib(delete2.obj) 中定义
1>	正在搜索 C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\kernel32.lib:
1>	正在搜索 C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\user32.lib:

看来解决的方式就是把nafxcw.lib提前编译,要让它提前编译,好的方式 就是加入依赖lib中,输入–>附加依赖项:nafxcw.lib
再测试下:

1>正在链接...
1>正在搜索库
1>	正在搜索 D:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\lib\nafxcw.lib:
1>	正在搜索 D:\Program Files\Microsoft Visual Studio 9.0\VC\lib\DelayImp.lib:
1>	正在搜索 C:\Program Files\Microsoft SDKs\Windows\v6.0A\\lib\uuid.lib:
1>	正在搜索 D:\Program Files\Microsoft Visual Studio 9.0\VC\lib\libcpmt.lib:

果然第一个被编译了,搞定


linux安装python依赖:[root@VM-16-5-centos noon]# pip3.6 install sqlalchemy WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3.6 install --user` instead. Collecting sqlalchemy Downloading http://mirrors.tencentyun.com/pypi/packages/5e/50/f63ff7811a8d3367a2c7fae6095f08da20e64e09762e4da1bf05706aefb1/SQLAlchemy-1.4.54-cp36-cp36m-manylinux1_x86_64.manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_5_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6MB) 100% |████████████████████████████████| 1.6MB 1.8MB/s Collecting greenlet!=0.4.17; python_version >= "3" and (platform_machine == "aarch64" or (platform_machine == "ppc64le" or (platform_machine == "x86_64" or (platform_machine == "amd64" or (platform_machine == "AMD64" or (platform_machine == "win32" or platform_machine == "WIN32")))))) (from sqlalchemy) Downloading http://mirrors.tencentyun.com/pypi/packages/1e/1e/632e55a04d732c8184201238d911207682b119c35cecbb9a573a6c566731/greenlet-2.0.2.tar.gz (164kB) 100% |████████████████████████████████| 174kB 920kB/s Collecting importlib-metadata; python_version < "3.8" (from sqlalchemy) Downloading http://mirrors.tencentyun.com/pypi/packages/a0/a1/b153a0a4caf7a7e3f15c2cd56c7702e2cf3d89b1b359d1f1c5e59d68f4ce/importlib_metadata-4.8.3-py3-none-any.whl Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->sqlalchemy) Downloading http://mirrors.tencentyun.com/pypi/packages/bd/df/d4a4974a3e3957fd1c1fa3082366d7fff6e428ddb55f074bf64876f8e8ad/zipp-3.6.0-py3-none-any.whl Requirement already satisfied: typing-extensions>=3.6.4; python_version < "3.8" in /usr/local/lib/python3.6/site-packages (from importlib-metadata; python_version < "3.8"->sqlalchemy) Installing collected packages: greenlet, zipp, importlib-metadata, sqlalchemy Running setup.py install for greenlet ... error Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-xwpa9djj/greenlet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-5rl6bxpe-record/install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build/lib.linux-x86_64-3.6 creating build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/__init__.py -> build/lib.linux-x86_64-3.6/greenlet creating build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/__init__.py -> build/lib.linux-x86_64-3.6/greenlet/platform creating build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_generator.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_stack_saved.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_contextvars.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_greenlet.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_cpp.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_gc.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_extension_interface.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_version.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_throw.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_greenlet_trash.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_weakref.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_tracing.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/__init__.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/leakcheck.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_generator_nested.py -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/test_leaks.py -> build/lib.linux-x86_64-3.6/greenlet/tests running egg_info writing src/greenlet.egg-info/PKG-INFO writing dependency_links to src/greenlet.egg-info/dependency_links.txt writing requirements to src/greenlet.egg-info/requires.txt writing top-level names to src/greenlet.egg-info/top_level.txt reading manifest file 'src/greenlet.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no previously-included files found matching 'benchmarks/*.json' no previously-included directories found matching 'docs/_build' warning: no files found matching '*.py' under directory 'appveyor' warning: no previously-included files matching '*.pyc' found anywhere in distribution warning: no previously-included files matching '*.pyd' found anywhere in distribution warning: no previously-included files matching '*.so' found anywhere in distribution warning: no previously-included files matching '.coverage' found anywhere in distribution writing manifest file 'src/greenlet.egg-info/SOURCES.txt' copying src/greenlet/greenlet.cpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet.h -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_allocator.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_compiler_compat.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_cpython_compat.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_exceptions.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_greenlet.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_internal.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_refs.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_slp_switch.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_thread_state.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_thread_state_dict_cleanup.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/greenlet_thread_support.hpp -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/slp_platformselect.h -> build/lib.linux-x86_64-3.6/greenlet copying src/greenlet/platform/setup_switch_x64_masm.cmd -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_aarch64_gcc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_alpha_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_amd64_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_arm32_gcc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_arm32_ios.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_arm64_masm.asm -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_arm64_masm.obj -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_arm64_msvc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_csky_gcc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_m68k_gcc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_mips_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc64_aix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc64_linux.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc_aix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc_linux.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc_macosx.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_ppc_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_riscv_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_s390_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_sparc_sun_gcc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x32_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x64_masm.asm -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x64_masm.obj -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x64_msvc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x86_msvc.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/platform/switch_x86_unix.h -> build/lib.linux-x86_64-3.6/greenlet/platform copying src/greenlet/tests/_test_extension.c -> build/lib.linux-x86_64-3.6/greenlet/tests copying src/greenlet/tests/_test_extension_cpp.cpp -> build/lib.linux-x86_64-3.6/greenlet/tests running build_ext building 'greenlet._greenlet' extension creating build/temp.linux-x86_64-3.6 creating build/temp.linux-x86_64-3.6/src creating build/temp.linux-x86_64-3.6/src/greenlet gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python3.6m -c src/greenlet/greenlet.cpp -o build/temp.linux-x86_64-3.6/src/greenlet/greenlet.o gcc: error trying to exec 'cc1plus': execvp: 没有那个文件或目录 error: command 'gcc' failed with exit status 1 ---------------------------------------- Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-xwpa9djj/greenlet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-5rl6bxpe-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-xwpa9djj/greenlet/ [root@VM-16-5-centos noon]# python3.6 getSalerInfo3.py Traceback (most recent call last): File "getSalerInfo3.py", line 13, in <module> from sqlalchemy import exc, create_engine, text ModuleNotFoundError: No module named 'sqlalchemy' [root@VM-16-5-centos noon]#报错
06-19
BUG -- Linker flags (Release): -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined -- Linker flags (Debug): -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined -- ccache: NO -- Precompiled headers: NO -- Extra dependencies: dl m pthread rt -- 3rdparty dependencies: -- -- OpenCV modules: -- To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching ts video videoio -- Disabled: world -- Disabled by dependency: - -- Unavailable: java python2 python3 -- Applications: tests perf_tests apps -- Documentation: NO -- Non-free algorithms: NO -- -- GUI: GTK3 -- GTK+: YES (ver 3.24.20) -- GThread : YES (ver 2.64.6) -- GtkGlExt: NO -- VTK support: NO -- -- Media I/O: -- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11) -- JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80) -- WEBP: build (ver encoder: 0x020f) -- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37) -- TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver / ) -- JPEG 2000: OpenJPEG (ver 2.4.0) -- OpenEXR: /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2_3) -- HDR: YES -- SUNRASTER: YES -- PXM: YES -- PFM: YES -- -- Video I/O: -- DC1394: YES (2.2.5) -- FFMPEG: YES -- avcodec: YES (58.54.100) -- avformat: YES (58.29.100) -- avutil: YES (56.31.100) -- swscale: YES (5.5.100) -- avresample: NO -- GStreamer: YES (1.16.3) -- v4l/v4l2: YES (linux/videodev2.h) -- -- Parallel framework: pthreads -- -- Trace: YES (with Intel ITT) -- -- Other third-party libraries: -- VA: NO -- Lapack: NO -- Eigen: YES (ver 3.3.7) -- Custom HAL: NO -- Protobuf: build (3.19.1) -- -- OpenCL: YES (no extra features) -- Include path: /home/hyzk/Downloads/opencv-4.7.0/3rdparty/include/opencl/1.2 -- Link libraries: Dynamic load -- -- Python (for build): /usr/bin/python3 -- -- Java: -- ant: NO -- JNI: NO -- Java wrappers: NO -- Java tests: NO -- -- Install to: /usr/local
07-20
/usr/bin/cmake -S/home/zbt/S/sylar -B/home/zbt/S/sylar --check-build-system CMakeFiles/Makefile.cmake 0 /usr/bin/cmake -E cmake_progress_start /home/zbt/S/sylar/CMakeFiles /home/zbt/S/sylar/CMakeFiles/progress.marks make -f CMakeFiles/Makefile2 all make[1]: Entering directory '/home/zbt/S/sylar' make -f CMakeFiles/sylar.dir/build.make CMakeFiles/sylar.dir/depend make -f CMakeFiles/test_module.dir/build.make CMakeFiles/test_module.dir/depend make[2]: Entering directory '/home/zbt/S/sylar' cd /home/zbt/S/sylar && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/zbt/S/sylar /home/zbt/S/sylar /home/zbt/S/sylar /home/zbt/S/sylar /home/zbt/S/sylar/CMakeFiles/test_module.dir/DependInfo.cmake --color= make[2]: Entering directory '/home/zbt/S/sylar' [ 1%] Generating sylar/http/httpclient_parser.rl.cc [ 1%] Generating sylar/http/http11_parser.rl.cc make[2]: Leaving directory '/home/zbt/S/sylar' make -f CMakeFiles/test_module.dir/build.make CMakeFiles/test_module.dir/build cd /home/zbt/S/sylar/sylar/http cd /home/zbt/S/sylar/sylar/http ragel /home/zbt/S/sylar/sylar/http/http11_parser.rl -o /home/zbt/S/sylar/sylar/http/http11_parser.rl.cc -l -C -G2 --error-format=msvc make[2]: Entering directory '/home/zbt/S/sylar' make[2]: ragel: Command not found ragel /home/zbt/S/sylar/sylar/http/httpclient_parser.rl -o /home/zbt/S/sylar/sylar/http/httpclient_parser.rl.cc -l -C -G2 --error-format=msvc make[2]: ragel: Command not found make[2]: *** [CMakeFiles/sylar.dir/build.make:66: sylar/http/http11_parser.rl.cc] Error 127 make[2]: *** Waiting for unfinished jobs.... make[2]: *** [CMakeFiles/sylar.dir/build.make:71: sylar/http/httpclient_parser.rl.cc] Error 127 [ 1%] Generating sylar/uri.rl.cc [ 1%] Building CXX object CMakeFiles/test_module.dir/tests/test_module.cc.o cd /home/zbt/S/sylar/sylar /usr/bin/c++ -DDBUG_OFF -Dtest_module_EXPORTS -I/home/zbt/S/sylar/. -I/apps/sylar/include -I/usr/include/mysql -rdynamic -O3 -fPIC -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -Wno-deprecated-declarations -fPIC -o CMakeFiles/test_module.dir/tests/test_module.cc.o -c /home/zbt/S/sylar/tests/test_module.cc ragel /home/zbt/S/sylar/sylar/uri.rl -o /home/zbt/S/sylar/sylar/uri.rl.cc -l -C -G2 --error-format=msvc make[2]: ragel: Command not found make[2]: *** [CMakeFiles/sylar.dir/build.make:76: sylar/uri.rl.cc] Error 127 make[2]: Leaving directory '/home/zbt/S/sylar' make[1]: *** [CMakeFiles/Makefile2:247: CMakeFiles/sylar.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... [ 1%] Linking CXX shared library lib/libtest_module.so /usr/bin/cmake -E cmake_link_script CMakeFiles/test_module.dir/link.txt --verbose=1 /usr/bin/c++ -fPIC -rdynamic -O3 -fPIC -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -Wno-deprecated-declarations -shared -Wl,-soname,libtest_module.so -o lib/libtest_module.so CMakeFiles/test_module.dir/tests/test_module.cc.o -L/apps/sylar/lib -L/apps/sylar/lib64 make[2]: Leaving directory '/home/zbt/S/sylar' [ 1%] Built target test_module make[1]: Leaving directory '/home/zbt/S/sylar' make: *** [Makefile:87: all] Error 2
最新发布
07-22
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值