Я разрабатываю программу для Atmega328p в Atmel Studio 6.1
Это моя библиотека:
Файл cpp:
#include "lcd_16x2.h"
// default constructor
lcd_16x2::lcd_16x2()
{
} //lcd_16x2
// default destructor
lcd_16x2::~lcd_16x2()
{
} //~lcd_16x2
void lcd_16x2::lcd_init()
{
// Setto i pin della porta LCD ad output
LCD_DDR |= (1<< LCD_PIN_DATA) | (1 << LCD_PIN_CLK) | (1 << LCD_PIN_EN);
// LCD e SIPO disabilitato
LCD_EN_OFF();
LCD_CLK_OFF();
[...]
}
inline void lcd_16x2::shift_display_right()
{
lcd_wc(0x05);
}
[...]
Заголовочный файл:
#ifndef __LCD_16X2_H__
#define __LCD_16X2_H__#define F_CPU 16000000UL
#include <avr/io.h>
#include "avr/cpufunc.h"
#define LCD_DDR DDRB
#define LCD_PORT PORTB
[...]
#define LCD_CLK_OFF() (LCD_PORT &= ~(1 << LCD_PIN_CLK)) // Set clock SIPO to LOW
[...]#include <util/delay.h>
class lcd_16x2
{
//functions
public:
lcd_16x2();
~lcd_16x2();
void lcd_init();
inline void lcd_set_cursor(char line, char address);
inline void lcd_write_string(char *s);
inline void clear_display();
inline void return_home();
inline void shift_display_right();
protected:
private:
inline void lcd_write_bits_sipo(char d);
inline void lcd_wc(char data, char del = 42);
inline void lcd_wd(char data);
inline void lcd_enable_tik();}; //lcd_16x2
#endif //__LCD_16X2_H__
Когда у меня был только lcd_init () в качестве публичного метода в определении класса, все было в порядке и работало нормально. Затем я добавил другие методы в свой класс (clear_display (), shift_display_right () и т. Д.) И получил следующие ошибки:
Error 3 ld returned 1 exit status collect2.exe 0 0 LCD_driver
Error 2 undefined reference to `lcd_16x2::shift_display_right()' C:\Users\...\LCD_driver\LCD_driver\Debug/.././LCD_driver.cpp 20 1 LCD_driver
Выход:
------ Build started: Project: LCD_driver, Configuration: Debug AVR ------
Build started.
Project "LCD_driver.cppproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.1\Vs\Compiler.targets" from project "C:\Users\Alessio\Documents\Projects\LCD_driver\LCD_driver\LCD_driver.cppproj" (target "Build" depends on it):
Task "RunCompilerTask"C:\Program Files (x86)\Atmel\Atmel Studio 6.1\shellUtils\make.exe all
Building file: .././LCD_driver.cpp
Invoking: AVR8/GNU C Compiler : 3.4.4
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-g++.exe" -funsigned-char -funsigned-bitfields -DDEBUG -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328p -c -MD -MP -MF "LCD_driver.d" -MT"LCD_driver.d" -MT"LCD_driver.o" -o "LCD_driver.o" ".././LCD_driver.cpp"In file included from .././LCD_driver.cpp:10:0:
C:\Users\Alessio\Documents\Projects\LCD_driver\LCD_driver\lcd_16x2.h(51,14): inline function 'void lcd_16x2::shift_display_right()' used but never defined [enabled by default]
inline void shift_display_right();
^
Finished building: .././LCD_driver.cpp
Building target: LCD_driver.elf
Invoking: AVR8/GNU Linker : 3.4.4
"C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1056\avr8-gnu-toolchain\bin\avr-g++.exe" -o LCD_driver.elf lcd_16x2.o LCD_driver.o -Wl,-Map="LCD_driver.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mmcu=atmega328p
LCD_driver.o: In function `main':
C:\Users\Alessio\Documents\Projects\LCD_driver\LCD_driver\Debug/.././LCD_driver.cpp(20,1): undefined reference to `lcd_16x2::shift_display_right()'
collect2.exe(0,0): ld returned 1 exit status
make: *** [LCD_driver.elf] Error 1
The command exited with code 2.
Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "LCD_driver.cppproj" -- FAILED.
Done building project "LCD_driver.cppproj" -- FAILED.
Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
Я не могу понять проблему (до добавления некоторых методов все работало нормально!) …
Заранее спасибо
ПРИМЕЧАНИЕ: libm загружается в компоновщик …
Задача ещё не решена.