0
当我打电话GetProcessMemoryInfo我得到一个错误: 未定义的参考`GetProcessMemoryInfo”错误,MinGW的
我已经看到了这个问题:Undefined reference to [email protected]
但它不能解决我的问题。
我想知道我的进程在RAM中的大小是多少,所以我需要使用'GetProcessMemoryInfo'方法。
我的问题是,当我这样做时,链接会中断。
的CMakeLists.txt:
project(maxpath)
set(dir ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${dir}/build")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -static-libgcc -static-libstdc++ -static -m64 -lpsapi")
file(GLOB LIB_ALG algorithms/*.hpp)
file(GLOB LIB_DS datastructures/*.hpp)
file(GLOB LIB_LOG include/*.h)
set(GRID_GENERATOR
${LIB_ALG}
${LIB_DS}
${LIB_LOG}
grid/generator.cpp
grid/grid.hpp)
set(GRID_SOLVER
${LIB_ALG}
${LIB_DS}
${LIB_LOG}
grid/main_grid.cpp
grid/grid.hpp
include/memory_helper.cpp include/memory_helper.hpp include/fnv.h)
add_executable(gridGenerator ${GRID_GENERATOR})
add_executable(gridSolver ${GRID_SOLVER})
你可以看到,我用的是-lpsapi
说法,
我得到的错误是:
[ 33%] Linking CXX executable "some path...\gridSolver.exe"
CMakeFiles\gridSolver.dir/objects.a(memory_helper.cpp.obj):memory_helper.cpp:(.text+0xf1): undefined reference to `GetProcessMemoryInfo'
CMakeFiles\gridSolver.dir/objects.a(memory_helper.cpp.obj):memory_helper.cpp:(.text+0x131): undefined reference to `GetProcessMemoryInfo'
C:/PROGRA~1/MINGW-~1/X86_64~1.3-P/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\gridSolver.dir/objects.a(memory_helper.cpp.obj): bad reloc address 0x0 in section `.pdata'
C:/PROGRA~1/MINGW-~1/X86_64~1.3-P/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.3/../../../../x86_64-w64-mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [some path.../gridSolver.exe] Error 1
CMakeFiles\gridSolver.dir\build.make:121: recipe for target 'some path.../gridSolver.exe' failed
mingw32-make.exe[2]: *** [CMakeFiles/gridSolver.dir/all] Error 2
CMakeFiles\Makefile2:103: recipe for target 'CMakeFiles/gridSolver.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/gridSolver.dir/rule] Error 2
CMakeFiles\Makefile2:115: recipe for target 'CMakeFiles/gridSolver.dir/rule' failed
mingw32-make.exe: *** [gridSolver] Error 2
makefile:130: recipe for target 'gridSolver' failed
我与克利翁和MinGW工作-w64 \ x86_64-4.8.3-posix-seh-rt_v3-rev2 \ mingw64
有没有另一种方法o f这样做(除了使用psapi)?
感谢您的支持,现在我得到这个错误:为目标“gridSolver”指定链接库,该目标不是由该项目构建的。 – yossico
然后你提供的例子显然是错误的,或者你把它粘贴到了错误的位置,因为你的例子显然有一个'gridSolver'目标。如果您在'add_executable'之前添加了'target_link_libraries',请阅读cmake文档。 – Dutow
你是对的,我强烈地把它放在add_executable部分 – yossico