【问题标题】:No source available for "main()" error for c++ in EclipseEclipse 中 C++ 的“main()”错误没有可用的源
【发布时间】:2012-11-27 07:47:34
【问题描述】:

我知道以前很多人都问过这个问题,但我无法解决。我想在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)

【问题讨论】:

  • 你的代码中有 main() 吗?
  • 是的,我的每个 test.cpp 文件中都有一个。
  • 应该只有 1 个main 函数。您是否在编译器或链接器的命令行中包含了您的 test.cpp 文件?
  • 不,我不知道该怎么做。其他两个有main函数的测试文件我都删了,但是没什么区别

标签: c++ eclipse debugging


【解决方案1】:

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

CXXFLAGS=-g

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

...

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

....

您需要将此标志用于所有编译规则。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-01
    • 2016-07-23
    • 1970-01-01
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 2021-05-15
    相关资源
    最近更新 更多