makefile 中的错误:_start 的多个定义

2023-11-23

我尝试编写一个makefile:

    CC = g++
LD = ld
CFLAGS = -Wall -std=c++0x -O3
LDFLAGS = -lgsl -lgslcblas -lpthread

SOURCES = main.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLES = main

all: $(SOURCES) $(EXECUTABLES)
$(EXECUTABLES): $(OBJECTS)
    $(CC) $(OBJECTS) -o $@ $^ $(LDFLAGS) 

.cpp.o: 
    $(CC) $(CFLAGS) $< -o $@


.PHONY: clean
clean: 
    rm -f *~ *.o main

但是当我执行这段代码时,出现以下错误:

g++ -Wall -std=c++0x -O3 main.cpp -o main.o
main.cpp: In function ‘int main()’:
main.cpp:63:12: warning: unused variable ‘order’ [-Wunused-variable]
main.cpp:64:12: warning: variable ‘x’ set but not used [-Wunused-but-set-variable]
g++ main.o -o main main.o -lgsl -lgslcblas -lpthread 
main.o: In function `_start':
(.text+0x108): multiple definition of `_start'
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 10
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 10
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 20 has invalid symbol index 19
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:/build/buildd/eglibc-2.15/csu/../sysdeps/x86_64/elf/start.S:109: first defined here
main.o: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here
main.o:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
main.o: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here
main.o: In function `__data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o:(.data+0x0): first defined here
main.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here
main.o: In function `__libc_csu_fini':
(.text+0x7f0): multiple definition of `__libc_csu_fini'
main.o:(.text+0x7f0): first defined here
main.o: In function `_start':
(.text+0x108): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:/build/buildd/eglibc-2.15/csu/../sysdeps/x86_64/elf/start.S:109: first defined here
main.o: In function `Lagrange_coefficient(int, double, int, int)':
(.text+0x1f0): multiple definition of `Lagrange_coefficient(int, double, int, int)'
main.o:(.text+0x1f0): first defined here
main.o: In function `__data_start':
(.data+0x80): multiple definition of `datax'
main.o:(.data+0x80): first defined here
main.o: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here
main.o:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
main.o: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here
main.o: In function `Lagrange(double, double)':
(.text+0x3b0): multiple definition of `Lagrange(double, double)'
main.o:(.text+0x3b0): first defined here
main.o:(.bss+0x0): multiple definition of `std::cout@@GLIBCXX_3.4'
main.o:(.bss+0x0): first defined here
main.o: In function `__data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o:(.data+0x0): first defined here
main.o:(.dtors+0x8): multiple definition of `__DTOR_END__'
main.o:(.dtors+0x8): first defined here
main.o: In function `__libc_csu_init':
(.text+0x760): multiple definition of `__libc_csu_init'
main.o:(.text+0x760): first defined here
main.o: In function `__data_start':
(.data+0x20): multiple definition of `datay'
main.o:(.data+0x20): first defined here
main.o: In function `main':
(.text+0x0): multiple definition of `main'
main.o:(.text+0x0): first defined here
main.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
main.o:(.dtors+0x8): first defined here
/usr/bin/ld: error in main.o(.eh_frame); no .eh_frame_hdr table will be created.
/usr/bin/ld: error in main.o(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status
make: *** [main] Error 1

那么,我做错了什么,该如何解决呢?如果需要,我也可以添加我的代码。 (但是当我用以下代码编译它时,代码可以工作g++ -Wall -O3 -std=c++0x $1 -lgsl -lgslcblas.
谢谢你!


  g++ main.o -o main main.o -lgsl -lgslcblas -lpthread 
      ^^^^^^         ^^^^^^

你链接main.o两次,所以其中的所有内容都是重复的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

makefile 中的错误:_start 的多个定义 的相关文章

随机推荐

  • PHP读取cookie文件

    是否有任何帮助程序库可以读取 php ini 中的 cookie 文件 我的本地磁盘上有一个 cookie 文件 我想要一种更好的方式来读取它 我目前只是按行读取文件并解析出值 如果您打算阅读 Netscape 的格式 例如 curl 以这
  • 在调用堆栈中显示特殊的原始函数

    这个问题提示如下问题 有没有办法查看特殊原语调用堆栈中的函数 例如 创建一个在退出时返回调用堆栈的函数 myFun lt function obj on exit print sys calls return obj 调用此函数并将其结果分
  • 领域驱动设计自动递增实体键

    刚开始领域驱动设计 我了解到您应该使模型保持有效状态 并且在创建类的新实例时 建议将所有必需的属性作为构造函数参数 但是 当使用自动递增键时 当我从持久层调用 Add 方法时 我只会获得这个新 ID 如果我在没有密钥的情况下实例化我的对象
  • 捕获重复键插入异常

    我有一个带有唯一主键列的表 称为id 有时当我执行INSERT查询我收到错误 因为id值已被使用 我可以捕获这个特定错误吗try and catch 看起来 mysql 正在为重复的主键抛出 1062 错误代码 您可以检查 sql 异常的错
  • Angular 2,使用 href='#' 处理锚链接

    单击任何带有href Angular 路由器路径 path component NologinComponent pathMatch full 是匹配的 我应该如何处理这些锚链接以便锚与href 停留在同一页面 即什么都不做 锚标记示例 a
  • 是否可以在 Azure 应用服务上安装字体?

    我们正在使用 MigraDoc PDFsharp GDI 它依赖于将字体安装到系统中以便进行渲染 我们尝试过嵌入字体 但 MigraDoc 的 GDI 版本似乎不支持此功能 尝试将此组件移动到 Azure 应用服务时 它找不到字体 有没有办
  • 如何在 PyCharm 的运行/调试配置中将环境变量作为命令行参数传递?

    我正在尝试学习 PyCharm 需要将环境变量作为命令行参数传递给我的进程 例如执行相当于myScript py u myVar在 Linux 上 或者myScript py u myVar 在 Windows 上 如何在 PyCharm
  • 如果从静态构造函数启动并等待空的 .NET 任务,为什么不会完成?

    我不明白为什么下面的代码不起作用 var task new Task gt task Start if task Wait 10000 logger Info Works else logger Info Doesn t work 超时后
  • UIBarButtonItem 图标通过 IB 添加时为白色,以编程方式添加时为黑色

    当我将图标添加到UIBarButtonItem通过 Interface Builder 该图标显示为白色 当我以编程方式将相同的图标文件添加到另一个图标文件时UIToolbar 图标显示为黑色 为什么 UIImage image UIIma
  • Tesseract OCR:是否可以强制使用特定模式?

    我正在使用 Tesseract 我想开发一个能够识别字符序列的应用程序 我取得了不错的成绩 但并不出色 我想读取的字符序列有always一个特定的模式 比方说 数字数字数字字符字符 例如 123AB 有没有办法 告诉 ocr引擎结构始终是固
  • C# 理论:将 JMP 写入 asm 中的 codecave

    假设我已经使用以下命令分配了放置我的 codecave 的地址VirtualAllocEx 它返回地址 我使用以下命令将代码写入该地址WriteProcessMemory 这是问题 如何编写跳转到我的 Codecave 的跳转 我知道跳跃开
  • 按钮显示内联CSS

    我有以下 CSS 和 HTML http jsfiddle net 47w0h73r 6 one padding 20px background f00 two padding 20px background 00f a button fo
  • Jenkins 主/从配置

    我一直在阅读有关 Jenkins 主 从配置的信息 但我仍然有一些问题 是不是从机 Jenkins 并没有像主机 Jenkins 那样实际安装和启动 我假设我会以相同的方式安装一个主詹金斯和另一个从詹金斯 然后主詹金斯将控制从詹金斯 例如通
  • Visual Studio 2015 输出窗口丢失

    缺少显示 Visual Studio 中所有构建消息的输出窗口 我无法使用视图菜单将其恢复 我尝试了安全模式和诊断模式 然后重新启动了一切 怎样才能把窗户找回来 去引用MSDN 在 Visual Studio Express 版本中 输出
  • Rtti 访问复杂数据结构中的字段和属性

    正如已经讨论过的Delphi 2010 中的 Rtti 数据操作和一致性可以通过使用一对 TRttiField 和实例指针访问成员来达到原始数据和 rtti 值之间的一致性 对于仅具有基本成员类型 例如整数或字符串 的简单类 这将非常容易
  • 具有属性包装器的不可用属性

    我正在开发一个支持 iOS 14 及更高版本的应用程序 但我想使用一些 SwiftUI 3 属性包装器 例如 FocusState 我该如何解决这个问题Stored properties cannot be marked potential
  • D3.js v3 到 v4 刷机改动

    我希望从 d3v3 迁移到 d3v4 特别是我在迁移画笔时遇到困难 有人可以查看下面的链接并让我知道更改吗 http bl ocks org zanarmstrong ddff7cd0b1220bc68a58 我发现了一些变化 d3 tim
  • 为 MAUI Visual Studio 2022 安装 Android 工作负载时出现问题

    我已按照以下说明安装了 Visual Studio 2022 Preview 4 1 https learn microsoft com en us dotnet maui get started installation 我启动了一个新的
  • 如何检查输入是否为二进制格式(1 和 0)?

    我已经制作了一个程序 但是如果用户输入不是二进制格式 我想添加一个例外 我已经尝试了很多次添加例外 但似乎无法让它工作 下面是程序代码 如果有人可以提供帮助 我将不胜感激 import time error True n 0 while n
  • makefile 中的错误:_start 的多个定义

    我尝试编写一个makefile CC g LD ld CFLAGS Wall std c 0x O3 LDFLAGS lgsl lgslcblas lpthread SOURCES main cpp OBJECTS SOURCES cpp