我在Windows XP上使用Visual Studio 2005.我正在尝试使用"Google Test"框架.但由于链接器错误,我无法进行一次测试.
我在调试模式下使用/ MDd选项构建了Google Test源文件,而不是我创建了新项目.然后将此链接中的步骤写入项目属性文件.
比我尝试使用/ MDd选项构建调试模式并发生以下错误.你能帮帮忙吗?谢谢.
#include "gtest/gtest.h"
TEST(sample_test_case, sample_test)
{
EXPECT_EQ(1, 1);
}
int main(int argc, char** argv)
{
return 1;
}
1>------ Build started: Project: try3, Configuration: Debug Win32 ------
1>Compiling...
1>try3.cpp
1>Linking...
1>libcpmtd.lib(ios.obj) : error LNK2005: "private: static void __cdecl std::ios_base::_Ios_base_dtor(class std::ios_base *)" (?_Ios_base_dtor@ios_base@std@@CAXPAV12@@Z) already defined in msvcprtd.lib(MSVCP80D.dll)
1>libcpmtd.lib(ios.obj) : error LNK2005: "public: static void __cdecl std::ios_base::_Addstd(class std::ios_base *)" (?_Addstd@ios_base@std@@SAXPAV12@@Z) already defined in msvcprtd.lib(MSVCP80D.dll)
1>libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class …Run Code Online (Sandbox Code Playgroud) 我写了一个以下形式的程序:
#include "stuff_I_need.h"
int main(){
construct_array(); // uses OpenMP pragma's
print_array();
return(0);
}
Run Code Online (Sandbox Code Playgroud)
使用以下命令正确编译,链接和运行:
`gcc44 -I/home/matteson/sundials/include/ main.c -lm -L/home/matteson/sundials/lib -lsundials_cvode -lsundials_nvecserial -fopenmp -o /home/matteson/MPI_test/CVODE_test/main_test`
Run Code Online (Sandbox Code Playgroud)
"gcc44"只是gcc 4.4版本,因为它是在一个维护多个版本gcc的集群上编译的.库sundials_cvode和sundials_nvecserial用于在构造阵列期间求解几个微分方程.
现在,当我想转移到Matlab并尝试编译表单的mex文件时:
#include "stuff_I_need.h"
void mexFunction(int nlhs,mxArray* plhs[], int nrhs, const mxArray* prhs[]){
construct_array(); // uses OpenMP pragma's
print_array();
}
Run Code Online (Sandbox Code Playgroud)
并尝试在Matlab中使用以下命令进行编译:
>> mex -v CC="gcc44" CFLAGS="\$CFLAGS -I/home/matteson/sundials/include/ -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp -L/home/matteson/sundials/lib -lsundials_cvode -lsundials_nvecserial" mex_cvode.c
Run Code Online (Sandbox Code Playgroud)
我收到以下消息,最终导致链接错误:
-> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
FILE = /home/matteson/.matlab/R2010b/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /misc/linux/64/opt/pkg/matlab/R2010b
-> CC = gcc44 …Run Code Online (Sandbox Code Playgroud) 我有一个问题,我目前无法有效解决,因为我还不熟悉Metro应用程序开发.所以请忍受我:)
长话短说,我有一个大型,复杂的VS2012 Metro应用程序托管+本机解决方案(目前在Windows 8上构建)到面向Windows 8.1的VS2013中.
我将解决方案导入VS2013(在Windows 8.1上托管),并为其运行转换以及其中的所有子项目.Stuff编译,但是我们遇到问题就是链接器.这是我们得到的链接器错误的一个例子:
error LNK2019: unresolved external symbol __imp___beginthreadex referenced in function <blahblahblah>
error LNK2019: unresolved external symbol __imp___mbsrchr referenced in function <blahblahblah>
error LNK2019: unresolved external symbol _getenv referenced in function <blahblahblah>
error LNK2019: unresolved external symbol __imp___beginthreadex referenced in function <blahblahblah>
error LNK2019: unresolved external symbol __imp___endthreadex referenced in function <blahblahblah>
error LNK2019: unresolved external symbol __imp___mbsrchr referenced in function <blahblahblah>
error LNK2019: unresolved external symbol __imp___mbsnbicmp referenced in function <blahblahblah>
error LNK2019: unresolved …Run Code Online (Sandbox Code Playgroud) linker-errors microsoft-metro visual-studio-2013 windows-8.1
我在网上搜索但我还没有找到答案,为什么我收到这个错误:
错误1错误LNK2019:未解析的外部符号"public:class Mesh*__thiscall AssetManager :: GetAsset(class std :: basic_string,class std :: allocator>)"(?? $ GetAsset @ PAVMesh @@@ AssetManager @@ QAEPAVMesh @@ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@ Z)在函数"public:void __thiscall SceneManager :: AddMesh(class std :: basic_string, class std :: allocator>)"(?AddMesh @ SceneManager @@ QAEXV?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@ Z)C:\ Users\Dirk\documents\visual studio 2010\Projects\OpenGameEngine\OpenGameEngine\SceneManager.obj
这是我的代码:
AssetManager.h …
[更新] 很抱歉置顶,但首先了解这一点可能会有所帮助,因为它可能会改变问题。
\n\n这--wrap是链接器的一个选项ld,而不是gcc。
但我的 Eclipse 项目用于gcc链接阶段。
如何根据cmocka单元测试的需要使用包装函数?
我在用gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3。
我正在尝试使用此处--wrap指定的链接器选项,以便使用cmocka对 C 代码进行单元测试。
错误是
\n\nmake all \nBuilding target: unit_test_C_code_example_project\nInvoking: GCC C Linker\ngcc --wrap=add -o "unit_test_C_code_example_project" ./test_scripts/test_maths.o ./software_under_test/mocks/mock_add.o ./software_under_test/maths.o -lcmocka\ngcc: error: unrecognized option \xe2\x80\x98--wrap=add\xe2\x80\x99\nmake: *** [unit_test_C_code_example_project] Error 1\nRun Code Online (Sandbox Code Playgroud)\n\n因此,链接器抱怨该--wrap=add选项,但我不知道为什么。
不可避免的是,如果我不发布代码,有人会请求它,所以就在这里,尽管我怀疑它与链接器选项问题相关:
\n\n在我的单元测试主要中,我有
\n\nstatic void test_multiply_two_by_three(void **state)\n{\n will_return(__wrap_add(0, 2), 2);\n …Run Code Online (Sandbox Code Playgroud) 好的,我有这个代码:
str.c:
char *str = "example";
Run Code Online (Sandbox Code Playgroud)
main.c中:
int str(void);
int main(void)
{
str();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
生成文件:
CC = gcc
CFLAGS = -Wall -g
all: main
main: main.o str.o
main.o: main.c
str.o: str.c
clean:
rm -rf *.o main
Run Code Online (Sandbox Code Playgroud)
乍一看,有人可能会说这是一个未定义的参考错误或类似的东西.但编译器只接受此代码.
问题是,为什么我没有得到编译错误?
很明显,该功能没有正确定义.如果我使用gdb打破str()调用,我得到一个警告类型函数str未定义..
我正在尝试运行一个简单的 hello world 示例,并且已经需要一些时间来确定要使用的包含内容 现在我验证了包含路径,QApplication 实际上应该在那里,但它抛出了上述错误。为了清楚起见,我的代码:
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton *button = new QPushButton("Hello world!");
button->show();
return app.exec();
}
Run Code Online (Sandbox Code Playgroud)
我试图用第一编译QMAKE -project,然后QMAKE终于做出,然后得到了以下错误:
qt_hello_world.o: In function 'main':
undefined reference to QApplication::QApplication(int&, char**, int)
qt_hello_world.cpp: undefined reference to QPushButton::QPushButton(QString const&, QWidget*)
qt_hello_world.cpp: undefined reference to QWidget::show()
qt_hello_world.cpp: undefined reference to QApplication::exec()
qt_hello_world.cpp: undefined reference to QApplication::~QApplication()
qt_hello_world.cpp: undefined reference to QApplication::~QApplication()
Run Code Online (Sandbox Code Playgroud)
qmake 创建的 Makefile 包含正确的包含路径到包含 QtWidgets/QApplication 的 …
我正在使用 g++ 9.2.1 和 binutils 2.34。我正在运行 Manjaro 19.0.2 和 Linux 内核 5.4.23-1。一切都来自于我刚刚安装的全新 Manjaro,我认为这可以解决问题。
在编译以下超级简单的程序时:
#include <iostream>
int main()
{
std::cout << "Hello" << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我运行g++ main.cpp -o program,一切都很好,并且在执行 ./program 时我会收到 Hello。
但是,当我运行 g++ main.cpp -o main.o 时,它可以工作,但是当我运行 g++ main.o -o 程序时,出现以下错误:
/usr/bin/ld: main.o: _ZSt4cout: invalid version 3 (max 0)
/usr/bin/ld : main.o : error adding symbols: bad value
collect2: error: ld return 1 exit status
Run Code Online (Sandbox Code Playgroud)
我完全不知道它从哪里来。
我有一个包含两个文件的小项目:
主程序
#include <string>
template<int I>
int getint(int i)
{
extern std::string var;
return var.size() * i;
}
int main()
{
return getint<2>(2);
}
Run Code Online (Sandbox Code Playgroud)
和子.cpp
#include <string>
extern std::string var;
std::string var = "Hello";
Run Code Online (Sandbox Code Playgroud)
但是当我编译项目时,链接器给出了错误:
-------------- Clean: Debug in test (compiler: GNU GCC Compiler)---------------
Cleaned "test - Debug"
-------------- Build: Debug in test (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -g -c C:\Users\Fan\Downloads\test\test\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -Wall -fexceptions -g -c C:\Users\Fan\Downloads\test\test\sub.cpp -o obj\Debug\sub.o
mingw32-g++.exe -o bin\Debug\test.exe obj\Debug\main.o obj\Debug\sub.o
obj\Debug\main.o: In …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用集成到 Visual Studio 2019 的 LLVM 编译器构建OpenMP示例程序。
从这里下载LLVM编译器(版本10.0,win64),C:\Program Files\LLVM\bin添加到PATH环境变量中。LLVM 编译器工具链扩展是从Visual Studio Marketplace安装的。
它成功构建了一个 hello world 程序,但是当我尝试使用 OpenMP 时,链接器失败并出现以下错误:
1>clang version 10.0.0
1>Target: x86_64-pc-windows-msvc
1>Thread model: posix
1>InstalledDir: C:\Program Files\LLVM\bin
1> (in-process)
1> "C:\\Program Files\\LLVM\\bin\\clang-cl.exe" -cc1 -triple x86_64-pc-windows-msvc19.26.28805 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name llvmtest.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -D_DEBUG -D_MT -D_DLL --dependent-lib=msvcrtd --dependent-lib=oldnames -stack-protector 2 -fcxx-exceptions -fexceptions -fexternc-nounwind …Run Code Online (Sandbox Code Playgroud) linker-errors ×10
c++ ×4
openmp ×2
c ×1
clang ×1
compilation ×1
external ×1
function ×1
g++ ×1
gcc ×1
googletest ×1
ld ×1
linker-flags ×1
llvm ×1
lnk2005 ×1
matlab ×1
mex ×1
qapplication ×1
qt ×1
qt5 ×1
templates ×1
windows-8.1 ×1