我有一个非常简单的程序,它使用了门户网络编程接口 4.0 版中提供的功能(源代码请参见此处)。下面是我的代码
主.cxx:
#include <stdio.h>
#include <portals4.h>
int main() {
if (PtlInit() == PTL_OK) {
printf("Successfully initialized...\n");
PtlFini();
}
else {
printf("Failed to initialize...\n");
abort();
}
return 0;
}
生成文件:
.SUFFIXES: .cxx .o .h
CXX = g++
TARGET = test
SRCS = main.cxx
OBJS = $(SRCS:.cxx=.o)
PORTALS_ROOT = /home/brooks8/portals4
PORTALS_INCS = -I$(PORTALS_ROOT)/include
PORTALS_LIBS = -L$(PORTALS_ROOT)/lib -lportals -lportals_runtime
CXXFLAGS = -std=c++0x $(PORTALS_INCS)
LDFLAGS = $(PORTALS_LIBS)
%.o: %.cxx
$(CXX) -c $(CXXFLAGS) $<
$(TARGET) : $(OBJS)
$(CXX) -o $@ $^ $(LDFLAGS)
$(SRCS) : $(HEADERS)
clean :
rm -rf *.o $(TARGET)
当我运行时make
:
g++ -c -std=c++0x -I/home/brooks8/portals4/include main.cxx
g++ -o test main.o -L/home/brooks8/portals4/lib -lportals -lportals_runtime
main.o: In function `main':
main.cxx:(.text+0x5): undefined reference to `PtlInit()'
main.cxx:(.text+0x1d): undefined reference to `PtlFini()'
collect2: ld returned 1 exit status
make: *** [test] Error 1
我在我的主目录 ( /home/brooks8/portals4
) 中安装了 Portals 4.0,portals4.h
头文件位于/home/brooks8/portals4/include/portals4.h
. 在头文件中,这两个函数都得到了明确的定义,并且分别在第 38 页和第 39页的 Portals 4.0 规范(参见此处)中进行了定义。 Section 3.5.1
Secion 3.5.2
我不确定为什么我会收到未定义的引用,并希望对我的情况提供任何意见。如果我可以提供更多信息来帮助解决我的问题,请告诉我。
谢谢你。
编辑:
结果来自nm /home/brooks8/portals4/lib/libportals.a
:
...
libportals_ib_la-ptl_fat_lib.o:
0000000000000000 r .LC0
0000000000000000 r .LC1
000000000000000e r .LC2
0000000000000011 r .LC3
0000000000000070 T PtlFini
0000000000000080 T PtlInit
...
结果来自file main.o
:
main.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
结果来自file ~/portals4/lib/libportals.a
:
~/portals4/lib/libportals.a: current ar archive
中的目标文件~/portals/lib/libportals.a
:
libportals_ib_la-ptl_atomic.o
libportals_ib_la-ptl_buf.o
libportals_ib_la-ptl_conn.o
libportals_ib_la-ptl_ct.o
libportals_ib_la-ptl_ct_common.o
libportals_ib_la-ptl_data.o
libportals_ib_la-ptl_eq.o
libportals_ib_la-ptl_eq_common.o
libportals_ib_la-ptl_evloop.o
libportals_ib_la-ptl_fat_lib.o
libportals_ib_la-ptl_id.o
libportals_ib_la-ptl_iface.o
libportals_ib_la-ptl_init.o
libportals_ib_la-ptl_iov.o
libportals_ib_la-ptl_le.o
libportals_ib_la-ptl_md.o
libportals_ib_la-ptl_me.o
libportals_ib_la-ptl_misc.o
libportals_ib_la-ptl_move.o
libportals_ib_la-ptl_mr.o
libportals_ib_la-ptl_ni.o
libportals_ib_la-ptl_obj.o
libportals_ib_la-ptl_param.o
libportals_ib_la-ptl_pt.o
libportals_ib_la-ptl_recv.o
libportals_ib_la-ptl_tgt.o
libportals_ib_la-ptl_rdma.o
libportals_ib_la-ptl_iface_ib.o
libportals_ib_la-ptl_mem.o
libportals_ib_la-ptl_queue.o
libportals_ib_la-ptl_shmem.o
结果来自file XXXX.o
:
XXXX.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped