0

I've checked more or less all the answers to this kind of problem wich seems quite usual when compiling with the new llvm package but I couldn't find any solution.

MacBook-Air-di-Manfredo:SINGLE_TETRAMER manfredo$ clang++ -v -Wall -O3 -g -fpic -c -lm         grbyinsertion.cpp -I/Users/manfredo/Desktop/tesi/codice_tesi/oxDNA/src/Observables
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
clang: warning: -lm: 'linker' input unused
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -disable-free -disable-llvm-verifier -main-file-name grbyinsertion.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -gdwarf-2 -coverage-file /Users/manfredo/Desktop/tesi/codice_tesi/SINGLE_TETRAMER/grbyinsertion.o -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1 -isysroot     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -I /Users/manfredo/Desktop/tesi/codice_tesi/oxDNA/src/Observables -stdlib=libc++ -O3 -Wall -fdeprecated-macro -fdebug-compilation-dir /Users/manfredo/Desktop/tesi/codice_tesi/SINGLE_TETRAMER -ferror-limit 19 -fmessage-length 121 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o grbyinsertion.o -x c++ grbyinsertion.cpp
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin13.1.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Users/manfredo/Desktop/tesi/codice_tesi/oxDNA/src/Observables
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks (framework directory)
End of search list.
grbyinsertion.cpp:63:9: warning: unused variable 'box_side' [-Wunused-variable]
        number box_side = *this->_config_info.box_side;
               ^
grbyinsertion.cpp:156:16: note: in instantiation of member function 'grbyinsertion<float>::init' requested here
template class grbyinsertion<float>;
               ^
grbyinsertion.cpp:63:9: warning: unused variable 'box_side' [-Wunused-variable]
        number box_side = *this->_config_info.box_side;
               ^
grbyinsertion.cpp:157:16: note: in instantiation of member function     'grbyinsertion<double>::init' requested here
template class grbyinsertion<double>;
               ^
2 warnings generated.

MacBook-Air-di-Manfredo:SINGLE_TETRAMER manfredo$ clang++ -v -shared -o grbyinsertion.so grbyinsertion.o -g2
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -dylib -arch x86_64 -macosx_version_min 10.9.0 -syslibroot     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -o grbyinsertion.so grbyinsertion.o -lc++ -lSystem     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "_getInputFloat", referenced from:
      grbyinsertion<float>::get_settings(input_file&, input_file&) in grbyinsertion.o
      grbyinsertion<double>::get_settings(input_file&, input_file&) in grbyinsertion.o
  "_getInputInt", referenced from:
      grbyinsertion<float>::get_settings(input_file&, input_file&) in grbyinsertion.o
      grbyinsertion<double>::get_settings(input_file&, input_file&) in grbyinsertion.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The function getinputfloat is defined in an header file like so:

int getInputFloat(input_file *inp, const char *skey, float *dest, int mandatory) {
    int key = getInputKeyIndex(inp, skey, mandatory);
    if(key != KEY_NOT_FOUND) *dest = atof(inp->values[key]);
    else return KEY_NOT_FOUND;

    return KEY_FOUND;
}

and is called by my program like so:

template<typename number>
void grbyinsertion<number>::get_settings(input_file &my_inp, input_file &sim_inp) {
    float tmp;
    if(getInputFloat(&my_inp, "bin", &tmp, 0) == KEY_FOUND) _bin = tmp;

    getInputInt(&my_inp, "insertions", &_insertions, 0);
    getInputFloat(&sim_inp, "T", &tmp, 1);
    _T = tmp;

    if(getInputFloat(&my_inp, "gr_min", &tmp, 0) == KEY_FOUND) _min = tmp;
    if(getInputFloat(&my_inp, "gr_max", &tmp, 0) == KEY_FOUND) _max = tmp;

}

I've actually noticed that the header file where the getinputfloat function is defined is a .c file while most (i thought all of them) of the other files are .cpp, could this be the problem?

My llvm version is the 3.5 and I've upgraded all ports installed (via macports). Thanks.

Manfredo
  • 1,760
  • 4
  • 25
  • 53
  • 1
    I don't see any error messages about undefined symbols. (But do put `-lm` at the end.) – kec May 05 '14 at 13:54
  • All I see is two warnings about unused variables (which come from two instantiations of the same template). Did you miss part of the error message? – molbdnilo May 05 '14 at 14:02
  • Do you know where `getInputFloat` should be coming from? If not and you know how to use the `find` command, search all the header files on your computer for `getInputFloat`. Also, move `-lm` to the end as I mentioned in the first comment. – kec May 05 '14 at 14:28
  • Function getInputFloat is defined in an external header but with other classes calling it it doesn't show any problems. I moved the -lm flag at the end but it doesn't change anything – Manfredo May 05 '14 at 14:39
  • Okay, so if you know which header it's coming from, then you need to verify that the associated .o or library is included in your link. If you believe that it is in fact included in your link, then use the `nm` command to verify that it really is. – kec May 05 '14 at 14:44
  • the nm command shows up a U(undefined) close to getinputfloat – Manfredo May 05 '14 at 16:20
  • By the way, when compiling this on a remote host with g++ it actually works fine and the nm shows up a very similar output for the .o file – Manfredo May 05 '14 at 16:27
  • Please show how these functions are defined and how they are used. – Anton Korobeynikov May 06 '14 at 06:15
  • In fact I managed to fix the problem by providing the .o file adress directly in the linking but I still can't figure out why is this happening – Manfredo May 06 '14 at 10:02

0 Answers0