c++ - Eclipse 中的 c++ 没有可用的 "main()"错误源

标签 c++ eclipse debugging

我知道之前有很多人问过这个问题,但我一直无法解决。我想在 eclipse 中调试一个 makefile 项目,但我不能。我刚学c++,不会写makefile,老师给了我一个,贴在下面。我该如何解决这个错误?

另外,如果对大家有帮助的话,我只想调试DijkstraTest.cpp主函数,其他的都不调试。

# first name a variable objects for all object files
# FOR strauss
#CXX = CC

objectsqueue = LinkedList.o

objectstestqueue = QueueTests.o

objectsheap = BinaryHeap.o

objectstestheap = BinaryHeapTest.o

objectsdijkstra = CSV.o Network.o Dijkstra.o

objectstestdijkstra = DijkstraTest.o

# name a variable sources for all source files

sourcesqueue = LinkedList.cpp

sourcestestqueue = QueueTests.cpp

sourcesheap = BinaryHeap.cpp

sourcestestheap = BinaryHeapTest.cpp

sourcesdijkstra = CSV.cpp Network.cpp Dijkstra.cpp

sourcestestdijkstra = DijkstraTest.cpp

# now make default target all exe files
all: testqueue testheap testdijkstra

# list the dependencies for object files - those header files which help build objects
LinkedList.cpp: Collection.h Stack.h Queue.h
QueueTests.o: QueueTests.cpp LinkedList.cpp
BinaryHeap.o: BinaryHeap.h 
BinaryHeapTest.o: BinaryHeap.h 
Dijkstra.o: CSV.h Dijkstra.h Network.h BinaryHeap.h 

# how to build all object files from all dependent source files

$(objectsqueue): $(sourcesqueue)
$(CXX) -c $(sourcesqueue) $(INCLUDES)

$(objectstestqueue): $(sourcestestqueue)
$(CXX) -c $(sourcestestqueue) $(INCLUDES)

$(objectsheap): $(sourcesheap)
$(CXX) -c $(sourcesheap) $(INCLUDES)

$(objectstestheap): $(sourcestestheap)
$(CXX) -c $(sourcestestheap) $(INCLUDES)

$(objectsdijkstra): $(sourcesdijkstra)
$(CXX) -c $(sourcesdijkstra) $(INCLUDES)

$(objectstestdijkstra): $(sourcestestdijkstra)
$(CXX) -c $(sourcestestdijkstra) $(INCLUDES)

clean:
rm -f *.o
rm -f *.exe

testqueue:  $(objectsqueue) $(objectstestqueue)
$(CXX) -o QueueTests.exe $(objectsqueue) $(objectstestqueue)

testheap: $(objectsheap) $(objectstestheap) 
$(CXX) -o BinaryHeapTest.exe $(objectsheap) $(objectstestheap)

testdijkstra: $(objectsheap) $(objectsdijkstra) $(objectstestdijkstra) 
$(CXX) -o DijkstraTest.exe $(objectsheap) $(objectsdijkstra) $(objectstestdijkstra)

最佳答案

为了能够调试应用程序,您需要使用 -g(调试)标志对其进行编译:

CXXFLAGS=-g

$(objectsqueue): $(sourcesqueue)
$(CXX) $(CXXFLAGS) -c $(sourcesqueue) $(INCLUDES)

...

testqueue:  $(objectsqueue) $(objectstestqueue)
$(CXX) $(CXXFLAGS) -o QueueTests.exe $(objectsqueue) $(objectstestqueue)

....

您需要为所有编译规则使用此标志。

关于c++ - Eclipse 中的 c++ 没有可用的 "main()"错误源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13574938/

相关文章:

c++ - Windows 上 Mingw 的 DLL 依赖项

c++ - 结构 ifreq : different definition in "linux/if.h" and man page

c++ - ConsoleApplication4.exe 已停止工作。 Windows 将关闭程序并通知是否有可用的解决方案

java - 如何从正在运行的生产 Tomcat Web 应用程序中获取线程调试信息?

c - C编译器中是否有 Debug模式编译标志的标准?

c++ - C++ Cmake的OpenCV

java - 在 Eclipse 中导出多个 jar

eclipse - 由于只读属性,在 tomcat 安装基础中分配临时目录导致错误

android - 哪个代码正在运行我当前看到的 UI

c - gdb 命令出错。 eclipse调试问题