Xcode C++ :: Duplicate Symbols for Architecture x86

I am new to Xcode and when I build the following code (an MWE), I get the following error ld: 3 duplicate symbols for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) I have three files as following; main.cpp #include "B.cpp" int main() { square(5); return 0; } B.cpp #include "A.cpp" void square(int n){ display(n*n); } A.cpp #in

Xcode C ++ ::体系结构x86的重复符号

我是Xcode的新手,当我构建下面的代码(MWE)时,出现以下错误 ld:体系结构x86_64的3个重复符号clang:error:linker命令失败,退出代码1(使用-v查看调用) 我有三个文件如下; main.cpp中 #include "B.cpp" int main() { square(5); return 0; } B.cpp #include "A.cpp" void square(int n){ display(n*n); } A.cpp #include <iostream> using namespace std; void display(int num){ cout<<n

Why won’t this simple C++ code compile with clang++?

This question already has an answer here: What is an undefined reference/unresolved external symbol error and how do I fix it? 27 answers main.cpp includes test.h ; it does not include test.cpp . You can compile and link them at the same time by specifying them both as input: [test]$ clang++ main.cpp test.cpp -o main你错过了其他的cpp文件: clang++ main.cpp test.cpp -o main

为什么不能用clang ++编译这个简单的C ++代码?

这个问题在这里已经有了答案: 什么是未定义的引用/未解析的外部符号错误,我该如何解决它? 27个答案 main.cpp包含test.h ; 它不包含test.cpp 。 您可以通过将它们同时指定为输入来同时编译和链接它们: [test]$ clang++ main.cpp test.cpp -o main你错过了其他的cpp文件: clang++ main.cpp test.cpp -o main

C++ libPNG

I am getting the following error when trying to compile.... Undefined symbols for architecture x86_64: "_png_sig_cmp", referenced from: RenderUtils::isValidPng(std::istream&) in RenderUtils.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) my code is as follows: //called from here ifstream s; s.open

C ++ libPNG

尝试编译时出现以下错误.... 体系结构x86_64的未定义符号:“_png_sig_cmp”,引用来自RenderUtils.o中的RenderUtils :: isValidPng(std :: istream&)ld:体系结构x86_64未找到符号ng:错误:链接器命令失败,退出代码为1使用-v来查看调用) 我的代码如下: //called from here ifstream s; s.open("/Users/tmg06qyu/Desktop/texture_512.png", ios::binary); if(!RenderUtils::isValidPng(s)){ throw 20; } //heade

static variable link error

I'm writing C++ code on a mac. Why do I get this error when compiling?: Undefined symbols for architecture i386: "Log::theString", referenced from: Log::method(std::string) in libTest.a(Log.o) ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation) Not sure if my code is wrong or I have to add additional flag

静态变量链接错误

我在Mac上编写C ++代码。 编译时为什么会出现这个错误?: 架构i386的未定义符号:“Log :: theString”,引用来自:libTest.a(Log.o)中的Log :: method(std :: string)ld:找不到架构i386的符号:clang:error:链接器命令失败,退出代码1(使用-v查看调用) 不知道我的代码是否错误,或者我不得不向Xcode添加额外的标志。 我当前的XCode配置是“静态库”项目的默认配置。 我的代码: Log.h ------------ #include &l

C++ lazy evaluation with templates

This question already has an answer here: Switch passed type from template 4 answers if(is_recursable<A>::value == 1) /* printf("1 %s", typeid(B).name()); */ lhs.printrec(); else printf("0"); Until constexpr if exists you cannot do this. Reason being is that the compiler must assume that both branches are possible even if one or the other is not reachable--yeah, seems like it sho

用模板进行C ++懒惰评估

这个问题在这里已经有了答案: 切换从模板4的答案传递类型 if(is_recursable<A>::value == 1) /* printf("1 %s", typeid(B).name()); */ lhs.printrec(); else printf("0"); 直到constexpr if存在,你不能这样做。 原因在于,编译器必须假设即使两个分支都不可达,两个分支都是可能的 - 好像它应该能够说明的一样,但是它不被语言所允许。 你需要使用标签调度或其他编译时构造。 看到这个答案

Visual C++ Odeint integrate

I'm trying to use integrate_const in Visual C++, as part of a class with an overloaded operator() . Why is the compiler failing to specialize the template? size_t steps = boost::numeric::odeint::integrate_const(stepper, *this, x, tbegin, tfinal, dt, obs); I'm getting IntelliSense and compilation errors saying: no instance of overloaded function "boost::numeric::odeint::integrate

Visual C ++ Odeint集成

我试图在Visual C ++中使用integrate_const ,作为带有重载operator()的类的一部分。 为什么编译器无法专门化模板? size_t steps = boost::numeric::odeint::integrate_const(stepper, *this, x, tbegin, tfinal, dt, obs); 我收到了IntelliSense和编译错误: 没有重载函数“boost :: numeric :: odeint :: integrate_const”的实例匹配参数列表c: Users ... src duffing.cpp 81 此外,它给出了消息: 错误C2893未能

C++ Header files and compilation process

I have a question about c++ header files and their includes. Consider the following scenario. I have a following files and code inside : Ah class A { // ... }; A.cpp #include "A.h" // implementation of A Bh class B { A object; } B.cpp #include "A.h" #include "B.h" /// implementation of B When I try to build, the compiler gives an error in Bh, that can't recognize A

C ++头文件和编译过程

我有一个关于c ++头文件及其包含的问题。 考虑以下情况。 我在里面有以下文件和代码: 啊 class A { // ... }; A.cpp #include "A.h" // implementation of A BH class B { A object; } B.cpp #include "A.h" #include "B.h" /// implementation of B 当我尝试编译时,编译器在Bh中给出了一个错误,它无法识别A,因为我没有包含Ah 问题是为什么编译器单独编译头文件,如果它们包含在一些cpp文件中

C++ palindrome debugging

I came across this question in my notes: Given an array of integers, write a function to check if the elements in that array are palindromes.I've been working on my code and it looks something like this: #include<iostream> #include<cmath> using namespace std; bool is_a_palindrome(int integers[], int length){ int i; int middle = floor(length / 2); //while (length !=

C ++回文调试

我在笔记中遇到了这个问题:给定一个整数数组,写一个函数来检查该数组中的元素是否是palindromes。我一直在研究我的代码,它看起来像这样: #include<iostream> #include<cmath> using namespace std; bool is_a_palindrome(int integers[], int length){ int i; int middle = floor(length / 2); //while (length != 0 && length > 0){ for (i = 0; i < middle; i++){ i

I don’t know why my string can't save the value

I am writing a C++ function to calculate Hex from Dec, but I don't know why my string can't save the value. Can anybody help me? string DecToHex(int a){ int i=0,j=0; string d,c; while(a!=0) { i=a%16; switch(i) { case 10: d[j]='A'; break; case 11: d[j]='B'; break; case 12: d[j]='C'; break; case 13

我不知道为什么我的字符串无法保存值

我正在编写一个C ++函数来从十二月计算Hex,但我不知道为什么我的字符串无法保存该值。 有谁能够帮助我? string DecToHex(int a){ int i=0,j=0; string d,c; while(a!=0) { i=a%16; switch(i) { case 10: d[j]='A'; break; case 11: d[j]='B'; break; case 12: d[j]='C'; break; case 13: d[j]='D'; break;

Basic c program not compiling in Ubuntu trusty

Respectful greetings, This basic C program does not compile in Ubuntu trusty 14.04.1 LTS. The compile line is gcc array.c -std=c99 (the last option for loops). Should I be using ? Is there an iostream for c (and not c++)? #include <stdio.h> #include <stdlib.h> using namespace std; int main(void) { int array[8]; for(int x=0;x<8;x++) { std::cin>>array[x];

基本的c程序不在Ubuntu中编译可靠

尊敬的问候, 这个基本的C程序不能在Ubuntu trusty 14.04.1 LTS中编译。 编译行是gcc array.c -std = c99(循环的最后一个选项)。 我应该使用吗? 有没有一个iostream的C(而不是C ++)? #include <stdio.h> #include <stdlib.h> using namespace std; int main(void) { int array[8]; for(int x=0;x<8;x++) { std::cin>>array[x]; } for(int x=0;x<8;x++) { std::cout&