[关闭]
@CrazyHenry 2018-04-20T14:50:18.000000Z 字数 1879 阅读 1224

faiss-尝试编译Hello World

hhhhfaiss


  1. #include <iostream>
  2. #include <string>
  3. using std::cout;
  4. using std::string;
  5. using std::ends;
  6. using std::endl;
  7. int main()
  8. {
  9. string s = "HelloWorld";
  10. cout<<s<<ends<<s<<endl;
  11. return 0;
  12. }

Makefile:

  1. MAKEFILE_INC=../../makefile.inc
  2. -include $(MAKEFILE_INC)
  3. NVCCLDFLAGS = -Xcompiler \"-Wl,-rpath=../../:../../gpu/\" \
  4. -L../.. -L../../gpu -lfaiss -lgpufaiss
  5. LDFLAGS = -L../.. -Wl,-rpath=../.. -lfaiss
  6. all: cpu gpu
  7. cpu: 1-Flat 2-IVFFlat 3-IVFPQ HelloWorld
  8. gpu: 4-GPU 5-Multiple-GPUs
  9. 1-Flat: 1-Flat.cpp ../../libfaiss.$(SHAREDEXT)
  10. $(CXX) -o $@ $(CXXFLAGS) $< -I../../../ $(LDFLAGS)
  11. 2-IVFFlat: 2-IVFFlat.cpp ../../libfaiss.$(SHAREDEXT)
  12. $(CXX) -o $@ $(CXXFLAGS) $< -I../../../ $(LDFLAGS)
  13. 3-IVFPQ: 3-IVFPQ.cpp ../../libfaiss.$(SHAREDEXT)
  14. $(CXX) -o $@ $(CXXFLAGS) $< -I../../../ $(LDFLAGS)
  15. 4-GPU: 4-GPU.cpp ../../libfaiss.$(SHAREDEXT) ../../gpu/libgpufaiss.$(SHAREDEXT)
  16. $(NVCC) $(NVCCFLAGS) -o $@ $< $(NVCCLDFLAGS) -I../../../
  17. 5-Multiple-GPUs: 5-Multiple-GPUs.cpp ../../libfaiss.$(SHAREDEXT) \
  18. ../../gpu/libgpufaiss.$(SHAREDEXT)
  19. $(NVCC) $(NVCCFLAGS) -o $@ $< $(NVCCLDFLAGS) -I../../../
  20. HelloWorld: HelloWorld.cpp ../../libfaiss.$(SHAREDEXT)
  21. $(CXX) -o $@ $(CXXFLAGS) $< -I../../../ $(LDFLAGS)
  22. ../../libfaiss.$(SHAREDEXT):
  23. cd ../../ && make libfaiss.$(SHAREDEXT)
  24. ../../gpu/libgpufaiss.$(SHAREDEXT):
  25. cd ../../gpu/ && make libgpufaiss.$(SHAREDEXT)
  26. clean:
  27. rm -f 1-Flat 2-IVFFlat 3-IVFPQ 4-GPU 5-Multiple-GPUs HelloWorld

新建目录test:

image_1cbgrhr0r1taq10l21ts9f9s1uv19.png-30.4kB

test目录下创建HelloWorld.cpp,写入代码:

cpp目录下

make HelloWorld

然后可执行程序会出现在test目录下
image_1cbgrultg1imq1ie01bls1d2817bf3m.png-119.5kB

cpp目录下执行./test/HelloWorld:

  1. ./test/HelloWorld

cpp目录下 make clean

  1. make clean

image_1cbgs6ng11vj01l5g409153114k553.png-104.8kB

Makefile的修改:

  1. 添加:
  2. HelloWorld: HelloWorld.cpp ../../libfaiss.$(SHAREDEXT)
  3. $(CXX) -o $@ $(CXXFLAGS) $< -I../../../ $(LDFLAGS)
  4. 修改:
  5. all: cpu gpu
  6. cpu: 1-Flat 2-IVFFlat 3-IVFPQ test/HelloWorld
  7. gpu: 4-GPU 5-Multiple-GPUs
  8. 修改:
  9. clean:
  10. rm -f 1-Flat 2-IVFFlat 3-IVFPQ 4-GPU 5-Multiple-GPUs test/HelloWorld

注意:建议Makefile的注释都只在行首打#

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注