我想用GPROF分析eclipse中的C ++代码。
我添加了我想用"new -> Makefile Project with Existing Code"
分析的代码,因为我从互联网上获得了它作为开源,现在我想对它进行分析。我第一次使用gprof和eclipse。
我的问题是,当我转到"project -> properties -> C/C++ build -> settings"
时,我看不到"Binary Parsers"
和"Error Parsers"
以外的任何内容。我无法为编译器和链接器添加标志(例如-pg
)。它可能与Makefile项目有关?!
(不幸的是,由于声誉较低,我无法添加我的屏幕截图)。
我现在如何使用gprof?我可以在其他地方向Compiler和Linker添加标志吗?
谢谢! aciams
编辑:
使用cmake创建了Makefile。因此,我向每个不以-pg
开头的文件添加了"# CMAKE generated file: DO NOT EDIT!"
。
当我再次构建项目时,我在
-pg
# compile CXX with /usr/bin/c++
CXX_FLAGS = -O3 -DNDEBUG -Wall -g -pg
但是当我运行程序并搜索名为"gmon.out"
的文件时,找不到任何内容。我是否必须明确地将-pg设置为链接器?
这是CMakeLists.txt的重要部分:
project()
#set ( CMAKE_BUILD_TYPE Debug )
set ( CMAKE_BUILD_TYPE Release )
#set ( CMAKE_CXX_COMPILER "icpc" )
#set ( CMAKE_CXX_COMPILER "g++-4.2" )
add_definitions ( -Wall -g -pg)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(${CMAKE_CXX_COMPILER} MATCHES "icpc")
set ( OPENMP_FLAG "-openmp" )
set ( OPENMP_LINK "-openmp" )
else()
set ( OPENMP_FLAG "-fopenmp" )
set ( OPENMP_LINK "-lgomp" )
endif(${CMAKE_CXX_COMPILER} MATCHES "icpc")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(${CMAKE_GENERATOR} MATCHES "Makefile")
find_package ( OpenMP REQUIRED )
set ( OPENMP_FLAG "-fopenmp" )
set ( OPENMP_LINK "-lgomp" )
#set ( APP_TYPE MACOSX_BUNDLE )
else()
set ( OPENMP_FLAG "-fopenmp" )
set ( OPENMP_LINK "" )
endif(${CMAKE_GENERATOR} MATCHES "Makefile")
else()
set ( OPENMP_FLAG "" )
set ( OPENMP_LINK "" )
endif()
set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set ( CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
/sw
/opt
/opt/local
/Users/$ENV{USER}/Development
./include
./lib
)
include ( ${QT_USE_FILE} )
include_directories (
${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
set ( EXECUTABLE_OUTPUT_PATH build/release )
set_source_files_properties ( test.cpp test2.cpp
PROPERTIES COMPILE_FLAGS ${OPENMP_FLAG}
)
add_executable ( )
target_link_libraries ()
install ( )
谢谢!