更改编程代码后出现链接错误

更改编程代码后出现链接错误

我有一个程序与某个数字生成器一起运行,我切换到另一个已经在 CUDA (CURAND) 中的程序,我尝试makefile相应地更改我的程序,但这导致了我无法理解的链接错误,这是我的main()

我收到以下错误:

nvcc -lm -lpthread main.o parser.o black_scholes.o -o hw1.x
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: main.o: in function `main':
main.c:(.text+0xe5): undefined reference to `black_scholes'
collect2: error: ld returned 1 exit status
make: *** [Makefile:24: hw1.x] Error 1

这是我的makefile

include Makefile.include


HW1_INCS = black_scholes.h parser.h timer.h util.h
HW1_C_SRCS = main.c parser.c
HW1_CUDA_SRCS = black_scholes.cu
HW1_C_OBJS = $(HW1_C_SRCS:.c=.o)
HW1_CUDA_OBJS = $(HW1_CUDA_SRCS:.cu=.o)
HW1_EXE = hw1.x

all: hw1.x

%.o: %.c
    $(CC) -c $(CCFLAGS) $(ACCFLAGS) $< -o $@

%.o: %.cu
    $(CC) -c $(CCFLAGS) $(ACCFLAGS) $< -o $@

hw1.x: $(HW1_C_OBJS) $(HW1_CUDA_OBJS)
    $(CC) $(LDFLAGS) $(HW1_C_OBJS) $(HW1_CUDA_OBJS) -o $@

black_scholes.o: black_scholes.cu black_scholes.h util.h
main.o: main.c black_scholes.h parser.h
parser.o: parser.c parser.h
util.o: util.c util.h

clean:
    rm -f $(HW1_C_OBJS) $(HW1_CUDA_OBJS) $(HW1_EXE)

这是我的makefile.include

CC = nvcc

COPTFLAGS = -O2

CPPFLAGS = 

CFLAGS = $(COPTFLAGS)

LINKER = nvcc

LDFLAGS = -lm -lpthread

如果相关的话,这是我的main()

#include "black_scholes.h"
#include "parser.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>


int main (int argc, char* argv[])
{
  confidence_interval_t interval;
  double S, E, r, sigma, T;
  int M = 0;
  char* filename = NULL;
  int nthreads = 1;
  double t1, t2;
  
  if (argc < 3)
    {
      fprintf (stderr, 
           "Usage: ./hw1.x <filename> <nthreads>\n\n");
      exit (EXIT_FAILURE);
    }
  filename = argv[1];
  nthreads = to_int (argv[2]);
  parse_parameters (&S, &E, &r, &sigma, &T, &M, filename);

  
  black_scholes (&interval, S, E, r, sigma, T, M, nthreads);

  printf ("Black-Scholes benchmark:\n"
      "------------------------\n"
      "S        %g\n"
      "E        %g\n"
      "r        %g\n"
      "sigma    %g\n"
      "T        %g\n"
      "M        %d\n",
      S, E, r, sigma, T, M);
  printf ("Confidence interval: (%g, %g)\n", interval.min, interval.max);

  return 0;
}

我已经清楚地链接black_scholes在一起,main()所以我不太明白为什么会发生这种情况,当我从代码中删除旧的数字生成器时,它就开始发生,并且即使在进行了适当的更改之后仍然继续发生make,任何修复方面的帮助make将不胜感激

相关内容