Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Xcode用于通用构建的编译器选项有哪些?_C++_Xcode_Gcc_G++ - Fatal编程技术网

C++ Xcode用于通用构建的编译器选项有哪些?

C++ Xcode用于通用构建的编译器选项有哪些?,c++,xcode,gcc,g++,C++,Xcode,Gcc,G++,如下图所示 < >我选择了编译C++代码的通用体系结构。我现在想在终端上做同样的事情 我试着使用这些选项 -arch x86_64,-arch i386,-m32,-m64 但我一直得到以下错误 $ g++ -dynamiclib myclass.cc -I hashlib2plus/header/ -L hashlib2plus/lib/ -o myclass.so -v Apple LLVM version 7.0.2 (clang-700.1.81) Target: x86_64-app

如下图所示

< >我选择了编译C++代码的通用体系结构。我现在想在终端上做同样的事情

我试着使用这些选项 -arch x86_64,-arch i386,-m32,-m64

但我一直得到以下错误

$ g++ -dynamiclib myclass.cc -I hashlib2plus/header/ -L hashlib2plus/lib/ -o myclass.so -v
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name myclass.cc -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 253.9 -v -dwarf-column-info -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2 -I hashlib2plus/header/ -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/akshaythakare/temp/cpp_dll -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/xs/1kz_zcnj1v324_rkdx_ftbx00000gn/T/myclass-13c695.o -x c++ myclass.cc
clang -cc1 version 7.0.2 based upon LLVM 3.7.0svn default target x86_64-apple-darwin15.3.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 hashlib2plus/header
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -dylib -arch x86_64 -macosx_version_min 10.11.0 -o myclass.so -Lhashlib2plus/lib/ /var/folders/xs/1kz_zcnj1v324_rkdx_ftbx00000gn/T/myclass-13c695.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "sha512wrapper::sha512wrapper()", referenced from:
      MyClass::hashCheck() in myclass-13c695.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
MyClass.cc

#include "myclass.h"
#include <dlfcn.h>
#include <iostream>
#include <dirent.h>
#include <vector>
#include "hashlib2plus/header/hashlibpp.h"

// g++ -dynamiclib -flat_namespace myclass.cc -o myclass.so
// hashlib2plus/hl_sha2ext.cpp hashlib2plus/hl_sha512wrapper.cpp

using namespace std;

void hasher(std::string);
std::vector <std::string> vecFile;

extern "C" MyClass* create_object(){
    return new MyClass;
}

extern "C" void destroy_object(MyClass* object){
    delete object;
}

MyClass::MyClass(){}

std::string globalMasterHash = "sd239d023md302k23s02ssd239d023md302k23s02ssd239d023md302k23s02ssd239d023md302k23s02s";

int MyClass::hashCheck(){
    std::string masterHash = "";
    hashwrapper *myWrapper = new sha512wrapper();
    std::string parentDir = "./static/";
    hasher(parentDir);

    while(vecFile.empty() != true){
        std::string hash2 = myWrapper->getHashFromFile(vecFile.back());
        vecFile.pop_back();
        masterHash = myWrapper->getHashFromString(hash2 + masterHash);
    }

    std::cout << masterHash << std::endl;
    if(masterHash.compare(globalMasterHash) == 0){
        return 1;
    } else {
        return 0;
    }
    return 0;
}


void hasher(std::string curr_directory){
    DIR *dir;
    dirent *ent;
    if((dir = opendir(curr_directory.c_str())) != NULL){
        while ((ent = readdir(dir))!=NULL){
            if(ent->d_name[0] != '.'){
                std::string path = curr_directory + ent->d_name;
                if (ent->d_type == DT_DIR){
                    path += "/";
                    hasher(path);
                } else {
                    vecFile.push_back(path);
                }
            }
        }
    }
    return;
}
#包括“myclass.h”
#包括
#包括
#包括
#包括
#包括“hashlib2plus/header/hashlibpp.h”
//g++-dynamiclib-flat_名称空间myclass.cc-o myclass.so
//hashlib2plus/hl_sha2ext.cpp hashlib2plus/hl_sha512wrapper.cpp
使用名称空间std;
void散列器(std::string);
向量向量文件;
外部“C”MyClass*创建对象(){
返回新的MyClass;
}
外部“C”无效销毁对象(MyClass*对象){
删除对象;
}
MyClass::MyClass(){}
std::string globalMasterHash=“SD239D023MD302K23S02SD239D023MD302K23S02SD239D023MD302K23S02S02SSD239D023MD302K23S02S02S”;
int MyClass::hashCheck(){
std::string masterHash=“”;
hashwrapper*myWrapper=new sha512wrapper();
std::string parentDir=“/static/”;
hasher(parentDir);
while(vecFile.empty()!=true){
std::string hash2=myWrapper->getHashFromFile(vecFile.back());
vecFile.pop_back();
masterHash=myWrapper->getHashFromString(hash2+masterHash);
}
std::cout d_name;
如果(ent->d_类型==DT_目录){
路径+=“/”;
散列器(路径);
}否则{
vecFile.push_back(路径);
}
}
}
}
返回;
}

我正在链接的库

你的main在哪里?你没有链接到“hashlib2plus”库。@Caduchon我正在创建一个不需要main的动态库。@molbdnilo我已经为库包含了-i和-L,我是否缺少了什么?@user5734678
“-i”
指定了在其中搜索标题的路径<代码>“-L”指定在中搜索库的路径。您还需要使用
“-l”
指定要搜索的库。
#include "myclass.h"
#include <dlfcn.h>
#include <iostream>
#include <dirent.h>
#include <vector>
#include "hashlib2plus/header/hashlibpp.h"

// g++ -dynamiclib -flat_namespace myclass.cc -o myclass.so
// hashlib2plus/hl_sha2ext.cpp hashlib2plus/hl_sha512wrapper.cpp

using namespace std;

void hasher(std::string);
std::vector <std::string> vecFile;

extern "C" MyClass* create_object(){
    return new MyClass;
}

extern "C" void destroy_object(MyClass* object){
    delete object;
}

MyClass::MyClass(){}

std::string globalMasterHash = "sd239d023md302k23s02ssd239d023md302k23s02ssd239d023md302k23s02ssd239d023md302k23s02s";

int MyClass::hashCheck(){
    std::string masterHash = "";
    hashwrapper *myWrapper = new sha512wrapper();
    std::string parentDir = "./static/";
    hasher(parentDir);

    while(vecFile.empty() != true){
        std::string hash2 = myWrapper->getHashFromFile(vecFile.back());
        vecFile.pop_back();
        masterHash = myWrapper->getHashFromString(hash2 + masterHash);
    }

    std::cout << masterHash << std::endl;
    if(masterHash.compare(globalMasterHash) == 0){
        return 1;
    } else {
        return 0;
    }
    return 0;
}


void hasher(std::string curr_directory){
    DIR *dir;
    dirent *ent;
    if((dir = opendir(curr_directory.c_str())) != NULL){
        while ((ent = readdir(dir))!=NULL){
            if(ent->d_name[0] != '.'){
                std::string path = curr_directory + ent->d_name;
                if (ent->d_type == DT_DIR){
                    path += "/";
                    hasher(path);
                } else {
                    vecFile.push_back(path);
                }
            }
        }
    }
    return;
}