헤더참조와 Makefile에 관한 질문 올립니다. (답변좀 꼭 달아주셨으면 감사하겠습니다.)

jazzjung의 이미지

#include "servo.h"
 
int	main(void)
{
	t_firmata	*firmata;
	t_servo	*servo;
 
	firmata = firmata_new("/dev/ttyACM99");
	while(!firmata->isReady)
	firmata_pull(firmata);
	sleep(1);
	servo = servo_attach(firmata, 3);
	while (1)
	{
		servo->value = 45;
		servo_write(servo, servo->value);
		usleep(500 * 1000);
		servo->value = 135;
		servo_write(servo, servo->value);
		usleep(500 * 1000);
	}
}

이소스와 opencv facedetect 소스를 병합&수정하여 페이스 트래킹을 해보려고 하는데
아직 초보라 모르는게 많아서 대충 위치에 걸맞게 병합하여
Makefile을 이용해 make를 하게되면 에러가나서 질문을 올렸습니다
처음에는 sleep함수와 usleep함수가 was not declared in this scope 에러가 나타납니다
그래서 이 두함수를 주석처리 해봤는데

servo.cpp:(.text+0x6a): undefined reference to `firmata_new(char*)'
servo.cpp:(.text+0x82): undefined reference to `firmata_pull(s_firmata*)'
servo.cpp:(.text+0xa7): undefined reference to `servo_attach(s_firmata*, int)'
servo.cpp:(.text+0x65f): undefined reference to `servo_write(s_servo*, int)'
servo.cpp:(.text+0x688): undefined reference to `servo_write(s_servo*, int)'
collect2: error: ld returned 1 exit status

이런 오류가 뜨더라고요 링크가 안되는거같은데

페이스디텍트소스와 servo를 따로 돌리게되면 문제가 없는데 합치면 이렇습니다

페이스디텍트는 g++ -o facedetect facedetect.cpp `pkg-config --libs \opencv`

서보소스는 make파일로

all:

>>서보 원래메이크파일 gcc -L.. -I../includes servoTest.c -lfirmatac -o servotest.ex
gcc u3_shield_GPIO_sysfs.c -o extGPIO.ex
>>병합한 서보파일 g++ -L.. -I../includes servo.cpp -lfirmatac -o servo.ex `pkg-config --libs \opencv`

clean:
rm *.ex

re: clean all

distclean: clean

이런식으로 되있고 병합한 서보파일 make문구는 제가 그냥 합쳐본것입니다.

app에 참조되는 라이브러리가 하나 더 있고 Makefile도 있는데

program_NAME := firmatac
program_C_SRCS := $(wildcard src/*.c)
program_C_OBJS := ${program_C_SRCS:.c=.o}
program_OBJS := $(program_C_OBJS)
program_INCLUDE_DIRS := includes
program_LIBRARY_DIRS :=
program_LIBRARIES :=
 
CC = gcc
CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir))
LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir))
LDFLAGS += $(foreach library,$(program_LIBRARIES),-l$(library))
 
.PHONY: all clean distclean
 
all: $(program_NAME)
	ar rc libfirmatac.a $(program_OBJS)
 
$(program_NAME): $(program_OBJS)
#	$(CC) $(program_OBJS) -o $(program_NAME)
 
clean:
	@- $(RM) libfirmatac.a
	@- $(RM) $(program_NAME)
	@- $(RM) $(program_OBJS)
 
re: clean all
 
distclean: clean

이런구성으로 되있습니다.
공부하고 있지만 아직 지식이 많이부족해서 그런데 도와주시면 감사하겠습니다.

Anti-Lock의 이미지

C언어로 만든 함수를 C++언어에서 사용하려면
extern "C" {
//여기에 C함수 선언들...
}
이런식으로 선언될 필요가 있습니다.
보통 헤더파일에 이렇게 적어둡니다만, C컴파일러를 위해
#ifdef _cplusplus
extern "C" {
#endif
//여기에 C 함수 선언...
#ifdef _cplusplus
}
#endif
이런식으로 C 헤더파일이 수정되어야 합니다.

간단하게는,
C++ 소스!! 파일에서 C헤더파일을 인클루드할때
extern "C" { ... } 로 감싸주면 됩니다.

jazzjung의 이미지

감사합니다 ㅎㅎ

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.