Symbol(s) not found for architecture x86_64 - Cmake - Mac sierra
Vor kurzem habe ich begonnen ein neues Projekt in C++. Das problem ist, wenn ich versuche zu kompilieren bekomme ich eine Verknüpfung Fehler. Ich verbrachte den ganzen Tag heute versucht zu Debuggen, aber ich habe nicht wirklich eine gute Lösung zu finden überall. Wenn jemand helfen könnte, es wäre erstaunlich. Ich bin mit einem Mac Sierra.
parsing/methylation.h
#ifndef EPIRL_METHYLATION_H
#define EPIRL_METHYLATION_H
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
using namespace std;
namespace methylation {
struct MethLine {
string chr;
int coord;
char strand;
int methylated;
int un_methylated;
string context;
string tag;
};
string calculateMethylationByContext(
MethLine m_input[], int length,
int window_start, int window_end, int threshold);
void calculateMethylation(
const istream &methylation_stream,
const istream &coordinate_stream,
const ostream &output_stream
);
}
#endif //EPIRL_METHYLATION_H
parsing/methylation.cpp
#include "methylation.h"
namespace methylation {
string calculateMethylationByContext(
MethLine m_input[], int length,
int window_start, int window_end, int threshold) {
//rest of the code ...
}
}
main.cpp
#include <iostream>
#include <fstream>
#include "parsing/methylation.h"
using namespace std;
int main(int argc, char **argv) {
if (argc != 4) {
cout << "Invalid number of arguments..." << endl;
return 1;
}
char *methylation_file = argv[1];
char *coordinate_file = argv[2];
char *output_file = argv[3];
ifstream methylation_file_stream(methylation_file, ios::binary);
ifstream coordinate_file_stream(coordinate_file, ios::binary);
ofstream output_file_stream(output_file, ios::binary);
methylation::calculateMethylation(methylation_file_stream,
coordinate_file_stream, output_file_stream);
methylation_file_stream.close();
coordinate_file_stream.close();
output_file_stream.close();
return 0;
}
Benutze ich CLion für meine Programmierung. Wenn ich versuche, es zu bauen, mein cmake-Befehl funktioniert, aber wenn ich dann auf "make" bekomme ich die folgende Fehlermeldung:
Undefined symbols for architecture x86_64:
"methylation::calculateMethylation(std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_istream<char, std::__1::char_traits<char> > const&, std::__1::basic_ostream<char, std::__1::char_traits<char> > const&)", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [src] Error 1
make[2]: *** [CMakeFiles/src.dir/all] Error 2
make[1]: *** [CMakeFiles/src.dir/rule] Error 2
make: *** [src] Error 2
meine CMakeLists.txt - Datei sieht wie folgt aus:
cmake_minimum_required(VERSION 3.6)
project(src)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES
parsing/methylation.cpp
parsing/methylation.h
main.cpp)
add_executable(src ${SOURCE_FILES})
Wenn ich das cmake Befehl, meine Ausgabe ist diese:
-- The C compiler identification is AppleClang 8.0.0.8000042
-- The CXX compiler identification is AppleClang 8.0.0.8000042
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/sztankatt/Documents/University/PartIII/Project/epiRL/src
Ich sehe nicht ein, definition der
calculateMethylation
in dem code, den Sie liefern; es ist nur declaration diese Funktion wird in der parsing/methylation.h
.Zeigen Sie uns Sachen Bezug auf
calculateMethylationByContext
, aber Ihre Fehler im Zusammenhang mit der calculateMethylation
. Wo haben Sie diese Funktion ?
InformationsquelleAutor tomooka | 2016-11-22
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ihre
CMakeLists.txt
ist in Ordnung.Als @thomas-matthews @tsyvarev @nos wies darauf hin, in Ihre Kommentare, Ihre Beispiel-code fehlt ist die definition/Umsetzung von
methylation::calculateMethylation()
. Was Sie sehen, ist der zu erwartende Fehler mit Apple/clang in dieser situation.Hinzufügen einer dummy-Implementierung, oder kommentieren Sie den Aufruf in Ihrem
main.cpp
erlaubenmake
erfolgreich abgeschlossen.Vorausgesetzt, Sie haben eine korrekte Umsetzung
Nehmen wir an, Sie haben eine Implementierung des
methylation::calculateMethylation()
im code (vielleicht in einer anderen Datei). Die Faust Schritt im debugging-build-Fehler in CMake generierten Makefiles ist zu führen mit dem, der variabelVERBOSE
Satz einen wahren Wert, das heißt:make VERBOSE=1
.Betrachten Sie nun den link Schritt und sehen Sie, wenn Sie fehlende Elemente; vielleicht eine Bibliothek oder eine Objekt-Datei. Wenn dem so ist, wissen Sie jetzt, gehen Sie zurück und fügen Sie es zu Ihrem
CMakeLists.txt
Zusammenfassung
Den ersten Schritt im debugging-unerwartete build-Fehler mit CMake generierten Makefiles ausgeführt:
Dadurch erhalten Sie Einblick in das, was CMake hinter die kulissen.
InformationsquelleAutor nega
Überprüfen, welche compiler wird automatisch erkannt, die von CMAKE.
Können Sie nach, was CMAKE sagt, wenn Sie zunächst CMAKE?
Dies kann ein Hinweis für dein problem zu
Können Sie überprüfen, was passiert, wenn Sie versuchen, folgende: cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++
Genau der gleiche Fehler 🙁
Sie können versuchen, tun Sie Folgendes: target_link_libraries(src stdc++) Diese sollten sicherstellen, dass Ihr Projekt wird verknüpft mit der c++ - standard-Bibliothek...
BTW: Manchmal kann es hilfreich sein, reinigen Sie die CMAKE-Verzeichnis (rm -rf *) vor dem ausführen einer anderen cmake generation nennen, wie CMAKE manchmal hält zwischengespeicherten Variablen
InformationsquelleAutor Sebastian Reischl