我在我的项目中一直面临这个错误。该项目有许多子项目,子项目作为静态库部署。
我之前遇到过这个错误,但是为所有静态库和 .exe 配置相同的运行时库将帮助我摆脱它。大多数错误都消失了,但即使所有项目的配置都相同,静态库之一也会引发此错误。
错误说
Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MTd_StaticDebug' in application.obj flRenderServer D:\Projects\FLProject\RenderBox\singlegame_renderbox\Production\FantasticLeague\_Code\FLeague\flRenderServer\miniEngine.lib(miniEngine.obj) 1
Run Code Online (Sandbox Code Playgroud)
这很相似
Severity Code Description Project File Line Suppression State
Error LNK2038 mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in application.obj flRenderServer D:\Projects\FLProject\RenderBox\singlegame_renderbox\Production\FantasticLeague\_Code\FLeague\flRenderServer\miniEngine.lib(miniEngine.obj) 1
Run Code Online (Sandbox Code Playgroud)
除此之外,没有其他库给出任何错误。任何帮助将不胜感激,谢谢:)
如果我使用 pthread 函数,我必须在 GCC 上使用“-lpthread”参数以确保正确链接。但是,为什么 GCC 在链接其他标准函数时不需要额外的参数?示例:printf、scanf、POSIX 套接字等。
我试图找到下面代码的问题,需要知道链接器如何能够跟踪下面程序中的全局变量多重定义问题,我不太确定链接器内部如何执行检查,因此请求帮助澄清。
**hello.h**
#ifndef __HELLO_
#define __HELLO_
static int s = 20;
int g = 10;
#endif
Run Code Online (Sandbox Code Playgroud)
**cat hello1.c**
#include <stdio.h>
#include "hello.h"
//int g = 10;
int main()
{
g++;
s++;
printf("g : %d s : %d\n", g, s);
function();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
**cat hello2.c**
#include <stdio.h>
#include "hello.h"
//extern int g;
void function()
{
g++;
s++;
printf("g : %d s : %d\n", g, s);
}
Run Code Online (Sandbox Code Playgroud)
**gcc -save-temps hello1.c hello2.c -o hello**
hello2.o:(.data+0x4): multiple definition of `g'
hello1.o:(.data+0x4): first defined …Run Code Online (Sandbox Code Playgroud) 编辑:只是为了结束,这个问题原来是由于链接器中的错误造成的。微软在版本 17.4.3 中修复了该问题
我刚刚将 Visual Studio 实例从 17.3.6 更新到 17.4.0。然后我尝试了一个干净的解决方案构建。突然我的一个项目给了我链接器错误
8>pch.obj : error LNK2001: unresolved external symbol __imp___tls_index_?init@?1??lazy_init_num_threads@internal@at@@YAXXZ@4_NA
8>pch.obj : error LNK2001: unresolved external symbol __imp___tls_offset_?init@?1??lazy_init_num_threads@internal@at@@YAXXZ@4_NA
8>C:\Users\jmole\Documents\Dev\Main\Solutions\..\Mobile\x64\Debug\net6.0-windows\mld_v143.dll : fatal error LNK1120: 2 unresolved externals
Run Code Online (Sandbox Code Playgroud)
这让我完全困惑。当我打开详细链接时,我看到它在 MSVCRTD.lib 中找到各种类似的符号。例如。
2> Found _tls_index
2> Found __dyn_tls_init
Run Code Online (Sandbox Code Playgroud)
还有其他人遇到过这种情况吗?
我收到链接错误,我不确定它的含义.
这是错误
1> Main.obj:错误LNK2019:未解析的外部符号"public:void __thiscall BinaryHeap,class std :: allocator >>,class Comp,class std :: allocator >>> :: insert(class Item,class std :: allocator >> const&)"(?insert @?$ BinaryHeap @ V?$ Item @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@@ V ?$ @比较V'$ @的basic_string杜?$ @ char_traits @ d @@性病V'$ @分配器@ d @@ 2性病@@@@@@ QAEXABV?$ @项V'$ @的basic_string杜?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@@@ Z)在函数"public:void …
可能重复:
C++模板,未定义的引用
我有一个非常简单的程序,由三个文件组成,它们从普通数组构建向量:
//create.hpp
#ifndef CREATE_HPP_
#define CREATE_HPP_
#include <vector>
using namespace std;
template<class T>
vector<T> create_list(T uarray[], size_t size);
#endif /* CREATE_HPP_ */
Run Code Online (Sandbox Code Playgroud)
//create.cpp
#include "create.hpp"
template<class T>
vector<T> create_list(T uarray[], size_t size){
vector<T> ulist(uarray, uarray + size);
return ulist;
}
Run Code Online (Sandbox Code Playgroud)
//main.cpp
#include <vector>
#include <iostream>
#include "create.hpp"
using namespace std;
int main(){
char temp[] = { '/', '>' };
vector<char> uvec = create_list<char>(temp, 2);
vector<char>::iterator iter=uvec.begin();
for(;iter != uvec.end();iter++){
cout<<*iter<<endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
构建过程如下:
g++ -O0 -g3 …Run Code Online (Sandbox Code Playgroud) 我无法弄清楚为什么我收到这个错误.任何人都可以伸出援助之手.我需要在头文件中声明VideoCapture捕获并在Video.cpp中调用它
Video.h
class Video
{
public:
static VideoCapture capture;
//Default constructor
Video();
//Declare a virtual destructor:
virtual ~Video();
//Method
void Start();
private:
};
Run Code Online (Sandbox Code Playgroud)
Video.cpp
#include "StdAfx.h"
#include "Video.h"
#include "UserInfo.h"
#include "Common.h"
void Video::Start()
{
while(1)
{
Mat img;
bool bSuccess = capture.read(img); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "End of video" << endl;
break;
}
imshow("original video", img); //show the frame in "Original Video" window
if(waitKey(30) == 27) …Run Code Online (Sandbox Code Playgroud) 因此,我获得了一个带有入门代码的作业来实现一个链表(我已经成功完成了未分类的双向链表),并且在给定头文件的入门代码中有一个朋友声明似乎有允许的目标我使用cout语句打印链表.这是头文件; 请注意,我在私人部分写了一切.
#ifndef _LINKED_LIST_
#define _LINKED_LIST_
#include <ostream>
class LinkedList
{
public:
LinkedList();
~LinkedList();
void add(char ch);
bool find(char ch);
bool del(char ch);
friend std::ostream& operator<<(std::ostream& out, LinkedList& list);
private:
struct node
{
char data;
node * next;
node * prev;
};
node * head, * tail;
};
#endif // _LINKED_LIST_
Run Code Online (Sandbox Code Playgroud)
在main,这也是初学者代码的一部分,老师写道cout << list;,这让我相信头文件中的友元声明的目标是允许列表轻松地打印到控制台.通常我不在乎,但如果我不注释掉cout << list;语句,那么链接器会为每个实例提供以下错误cout << list;
app.o: In function 'main':
[code directory]/app.cpp:[line the statement is on]: undefined reference to …Run Code Online (Sandbox Code Playgroud) 我正在讨论如何调试一个我无法简化为最小例子的重大问题.
问题:我编译了链接到许多不同库的应用程序.标志包括:
-static-libstdc++ -static-libgcc -pipe -std=c++1z -fno-PIC -flto=10 -m64 -O3 -flto=10 -fuse-linker-plugin -fuse-ld=gold -UNDEBUG -lrt -ldl
编译器是gcc-7.3.0,针对binutils-2.30编译.Boost编译时使用与程序其余部分相同的标志,并静态链接.
当程序被链接时,我得到关于重定位的各种警告,指的是丢弃的部分,在我自己的代码和boost中.例如:
/tmp/ccq2Ddku.ltrans13.ltrans.o:<artificial>:function boost::system::(anonymous namespace)::generic_error_category::message(int) const: warning: relocation refers to discarded section
Run Code Online (Sandbox Code Playgroud)
然后,当我运行该程序时,它会使用回溯进行破坏:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff7345a49 in __run_exit_handlers () from /lib64/libc.so.6
#2 0x00007ffff7345a95 in exit () from /lib64/libc.so.6
#3 0x00007ffff732eb3c in __libc_start_main () from /lib64/libc.so.6
#4 0x000000000049b3e3 in _start ()
Run Code Online (Sandbox Code Playgroud)
尝试调用的函数指针是0x0.
如果我使用static-libstdc ++删除,链接器警告和运行时段错误就会消失.
如果我从c ++ 1z更改为c ++ 14,链接器警告和运行时段错误就会消失. …
我正在编写一个简单的引导程序,并且有一个getch功能。
char getch()
{
uint16_t inchar;
__asm__ __volatile__ ("int $0x16\n\t"
: "=a"(inchar)
: "0"(0x0));
return (char)inchar;
}
Run Code Online (Sandbox Code Playgroud)
我尝试了第一个显而易见的解决方案,即删除inchar变量对char的强制转换,但是当我打印它时,仍然返回char而不是代码。
我的println实现:
void println(char *str)
{
while (*str)
{
// AH=0x0e, AL=char to print, BH=page, BL=fg color
__asm__ __volatile__ ("int $0x10"
:
: "a" ((0x0e<<8) | *str++),
"b" (0x0000));
}
}
Run Code Online (Sandbox Code Playgroud)
链接描述文件:
ENTRY(start);
SECTIONS
{
. = 0x7C00;
.text : {
/* Place the code in hw.o before all other code */
boot.o(.text);
*(.text);
}
/* Place …Run Code Online (Sandbox Code Playgroud) linker-errors ×10
c++ ×7
gcc ×2
x86 ×2
assembly ×1
bootloader ×1
build-error ×1
c ×1
c++17 ×1
dll ×1
friend ×1
glibc ×1
gold-linker ×1
linker ×1
pthreads ×1
qt ×1
visual-c++ ×1