c ++体系结构的未定义符号x86_64:" function_name"参考

时间:2015-09-03 21:21:37

标签: c++ undefined x86-64 symbols

是的,我知道已经有几个问题需要详细说明,但我觉得我的问题并不是针对具体细节的。只是在脸上盯着我的东西,但我无法看到它。

我在Makefile中一起编译C和C ++文件。一切似乎运行正常,直到我得到名义错误,这与CFile2中的函数有关。

编译就像这样(带占位符名称):

g++ -c main.cpp
g++ -c Class.cpp
gcc -c CFile1.c
gcc -c CFile2.c
g++ main.o Class.o CFile1.o CFile2.o -lcurl

我的Class.cpp有一个Class.hpp,我的CFile1和CFile2都有.h文件。一切都位于同一目录中,它们都具有相同的标题保护结构。

#ifndef
#define

//Insert function prototypes here

#endif

我也只在Class.hpp中包含CFile1.h和CFile2.h。根据这些信息,我有什么遗漏?

1 个答案:

答案 0 :(得分:0)

也许你错过了c标题中的Prefix Verb URI Pattern Controller#Action posts GET /posts(.:format) posts#index POST /posts(.:format) posts#create new_post GET /posts/new(.:format) posts#new edit_post GET /posts/:id/edit(.:format) posts#edit post GET /posts/:id(.:format) posts#show PATCH /posts/:id(.:format) posts#update PUT /posts/:id(.:format) posts#update DELETE /posts/:id(.:format) posts#destroy root GET / pages#home new_user_session GET /account/sign_in(.:format) devise/sessions#new user_session POST /account/sign_in(.:format) devise/sessions#create destroy_user_session DELETE /account/sign_out(.:format) devise/sessions#destroy user_password POST /account/password(.:format) devise/passwords#create new_user_password GET /account/password/new(.:format) devise/passwords#new edit_user_password GET /account/password/edit(.:format) devise/passwords#edit PATCH /account/password(.:format) devise/passwords#update PUT /account/password(.:format) devise/passwords#update cancel_user_registration GET /account/cancel(.:format) devise/registrations#cancel user_registration POST /account(.:format) devise/registrations#create new_user_registration GET /account/sign_up(.:format) devise/registrations#new edit_user_registration GET /account/edit(.:format) devise/registrations#edit PATCH /account(.:format) devise/registrations#update PUT /account(.:format) devise/registrations#update DELETE /account(.:format) devise/registrations#destroy user_confirmation POST /account/confirmation(.:format) devise/confirmations#create new_user_confirmation GET /account/confirmation/new(.:format) devise/confirmations#new GET /account/confirmation(.:format) devise/confirmations#show user_unlock POST /account/unlock(.:format) devise/unlocks#create new_user_unlock GET /account/unlock/new(.:format) devise/unlocks#new GET /account/unlock(.:format) devise/unlocks#show calendar_posts GET /calendars/:calendar_id/posts(.:format) posts#index POST /calendars/:calendar_id/posts(.:format) posts#create new_calendar_post GET /calendars/:calendar_id/posts/new(.:format) posts#new GET /posts/:id/edit(.:format) posts#edit GET /posts/:id(.:format) posts#show PATCH /posts/:id(.:format) posts#update PUT /posts/:id(.:format) posts#update DELETE /posts/:id(.:format) posts#destroy calendars GET /calendars(.:format) calendars#index POST /calendars(.:format) calendars#create new_calendar GET /calendars/new(.:format) calendars#new edit_calendar GET /calendars/:id/edit(.:format) calendars#edit calendar GET /calendars/:id(.:format) calendars#show PATCH /calendars/:id(.:format) calendars#update PUT /calendars/:id(.:format) calendars#update DELETE /calendars/:id(.:format) calendars#destroy MacBook-Pro-de-Thibaud:calendy TXC$ rake routes Prefix Verb URI Pattern Controller#Action root GET / pages#home new_user_session GET /account/sign_in(.:format) devise/sessions#new user_session POST /account/sign_in(.:format) devise/sessions#create destroy_user_session DELETE /account/sign_out(.:format) devise/sessions#destroy user_password POST /account/password(.:format) devise/passwords#create new_user_password GET /account/password/new(.:format) devise/passwords#new edit_user_password GET /account/password/edit(.:format) devise/passwords#edit PATCH /account/password(.:format) devise/passwords#update PUT /account/password(.:format) devise/passwords#update cancel_user_registration GET /account/cancel(.:format) devise/registrations#cancel user_registration POST /account(.:format) devise/registrations#create new_user_registration GET /account/sign_up(.:format) devise/registrations#new edit_user_registration GET /account/edit(.:format) devise/registrations#edit PATCH /account(.:format) devise/registrations#update PUT /account(.:format) devise/registrations#update DELETE /account(.:format) devise/registrations#destroy user_confirmation POST /account/confirmation(.:format) devise/confirmations#create new_user_confirmation GET /account/confirmation/new(.:format) devise/confirmations#new GET /account/confirmation(.:format) devise/confirmations#show user_unlock POST /account/unlock(.:format) devise/unlocks#create new_user_unlock GET /account/unlock/new(.:format) devise/unlocks#new GET /account/unlock(.:format) devise/unlocks#show calendar_posts GET /calendars/:calendar_id/posts(.:format) posts#index POST /calendars/:calendar_id/posts(.:format) posts#create new_calendar_post GET /calendars/:calendar_id/posts/new(.:format) posts#new edit_calendar_post GET /calendars/:calendar_id/posts/:id/edit(.:format) posts#edit calendar_post GET /calendars/:calendar_id/posts/:id(.:format) posts#show PATCH /calendars/:calendar_id/posts/:id(.:format) posts#update PUT /calendars/:calendar_id/posts/:id(.:format) posts#update DELETE /calendars/:calendar_id/posts/:id(.:format) posts#destroy calendars GET /calendars(.:format) calendars#index POST /calendars(.:format) calendars#create new_calendar GET /calendars/new(.:format) calendars#new edit_calendar GET /calendars/:id/edit(.:format) calendars#edit calendar GET /calendars/:id(.:format) calendars#show PATCH /calendars/:id(.:format) calendars#update PUT /calendars/:id(.:format) calendars#update DELETE /calendars/:id(.:format) calendars#destroy

如果您编译c文件并想要与c ++链接,那么你可以添加extern "C",但是c编译器不能识别它,所以它必须是extern "C"

在标题的开头添加,在函数减速之前:

#ifdef __cplusplus

您也可以在每个功能之前添加它,如下所示:

#include <stdio> // and all other includes...
#ifdef __cplusplus
extern "C" {
#endif

void funnction_name1(); //sample 1
int funnction_name2(char* p); //sample 2

//must close the extern "C" block
#ifdef __cplusplus
}
#endif