I am trying to understand the underlying implementation of Pytorch following this blog 10  and here is a toy example:
// THlearning.c
#include <TH/TH.h>

int main()
{
    THFile *x_file = THDiskFile_new("x", "r", 0);
    THFile *y_file = THDiskFile_new("y", "r", 0);

    THFloatTensor *x = THFloatTensor_newWithSize1d(10);
    THFloatTensor *y = THFloatTensor_newWithSize1d(10);

    THFile_readFloat(x_file, x->storage);
    THFile_readFloat(y_file, y->storage);

    double result = THFloatTensor_dot(x, y) + THFloatTensor_sumall(x);

    printf("%f\n", result);

    THFloatTensor_free(x);
    THFloatTensor_free(y);
    THFile_free(x_file);
    THFile_free(y_file);
    return 0;
}

when I tried to compile this short code, link error occured:

clang: warning: treating ‘c’ input as ‘c++’ when in C++ mode, this behavior is deprecated [-Wdeprecated]
Undefined symbols for architecture x86_64:
"_THDiskFile_new", referenced from:
_main in THlearning-1f17a7.o
"_THFile_free", referenced from:
_main in THlearning-1f17a7.o
"_THFile_readFloat", referenced from:
_main in THlearning-1f17a7.o
"_THFloatTensor_dot", referenced from:
_main in THlearning-1f17a7.o
"_THFloatTensor_free", referenced from:
_main in THlearning-1f17a7.o
"_THFloatTensor_newWithSize1d", referenced from:
_main in THlearning-1f17a7.o
"_THFloatTensor_sumall", referenced from:
_main in THlearning-1f17a7.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 platform is MacOS and the version of Pytorch is 0.2, installed through Anaconda on Python2.7
I failed to link the missed libs manually and my modification on .bash_profile is:
# added by Anaconda2 4.4.0 installer
export PATH="/Users/$MYUSERNAME/anaconda/bin:$PATH"

# gcc head files
C_INCLUDE_PATH=$C_INCLUDE_PATH:/Users/$MYUSERNAME/anaconda/lib/python2.7/site-     packages/torch/lib/include:/Users/$MYUSERNAME/anaconda/include:/Users/$MYUSERNAME/anaconda/lib/python2.7/site-packages/torch/utils/ffi/../../lib/include/TH:/Users/$MYUSERNAME/anaconda/include/python2.7
export C_INCLUDE_PATH

# g++ head files
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/Users/$MYUSERNAME/anaconda/lib/python2.7/site-packages/torch/lib/include:/Users/$MYUSERNAME/anaconda/include:/Users/$MYUSERNAME/anaconda/lib/python2.7/site-packages/torch/utils/ffi/../../lib/include/TH:/Users/$MYUSERNAME/anaconda/include/python2.7
export CPLUS_INCLUDE_PATH

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/Users/$MYUSERNAME/anaconda/lib/python2.7/site-packages/torch/lib
export LD_LIBRARY_PATH

LIBRARY_PATH=$LIBRARY_PATH:/Users/$MYUSERNAME/anaconda/lib/python2.7/site-packages/torch/lib
export LIBRARY_PATH

I hope someone can help me solve this problem…