c-Atmel Studio 7-静态库未定义的函数引用



我有一个包含两个项目的解决方案:-静态库-可执行

Exec项目显然依赖于库。编译器可以知道库在哪里,我可以使用IO.c上除了内容之外的所有内容(比如定义的符号(。在输出文件夹中,我可以找到coplied IO.o,所以库构建得很好。错误肯定是在执行项目方面,但我不知道在哪里搜索。谷歌让我失败了,或者我搜索的方向不对。

静态库项目的结构如下:

ATMEGA2560
|-headers
| |-IO.h
|-source
| |-IO.c
|-ATMEGA2560.h

可执行项目的结构如下:

|-main.c

编译器包括路径:

../../ATMEGA2560/Release/headers <- IO.h
../../ATMEGA2560/Release/ <- ATMEGA2560.h

所有编译器选项

-x c -funsigned-char -funsigned-bitfields -DNDEBUG  -I"E:ATMEL7.0PacksatmelATmega_DFP1.3.300include" -I"../../ATMEGA2560/Release/headers" -I"../../ATMEGA2560/Release"  -O3 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -mrelax -Wall -Wextra -Wundef -mmcu=atmega2560 -B "E:ATMEL7.0PacksatmelATmega_DFP1.3.300gccdevatmega2560" -c -std=gnu99 -v -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" 

链接库:

libm
libATMEGA2560

链接库路径:

../../ATMEGA2560/Release <- libATMEGA2560.a

所有链接器选项:

-Wl,-static -Wl,-Map="$(OutputFileName).map" -Wl,--start-group -Wl,-lm -Wl,-lATMEGA2560  -Wl,--end-group -Wl,-L"../../ATMEGA2560/Release"  -Wl,--gc-sections -mrelax -mmcu=atmega2560 -B "E:ATMEL7.0PacksatmelATmega_DFP1.3.300gccdevatmega2560" -u _fstat -u _read -u _write 

ATMEGA2560.h

#ifndef ATMEGA2560_H_
#define ATMEGA2560_H_
#define F_CPU 16000000L
#include <avr/io.h>
#include <util/delay.h>
#include "headers/IO.h"
#endif 

IO.h

#ifndef IO_H_
#define IO_H_
void function_1(void);
#endif

IO.c

#include "../headers/IO.h"
void function_1(void){
return;
}

main.c

#include "ATMEGA2560.h"
int main(void)
{
function_1();
DDRB = 0b10000000; // configure pin 7 of PORTB as output (digital pin 13 on the Arduino Mega2560)
while(1)
{
PORTB = 0b10000000; // set 7th bit to HIGH
_delay_ms(1000);
PORTB = 0b00000000; // set 7th bit to LOW
_delay_ms(1000);
}
}

编译输出:

------ Build started: Project: ATMEGA2560, Configuration: Release AVR ------
Shell Utils Path E:ATMEL7.0shellUtils
E:ATMEL7.0shellUtilsmake.exe all 
Using built-in specs.
Reading specs from E:/ATMEL/7.0/Packs/atmel/ATmega_DFP/1.3.300/gcc/dev/atmega2560/device-specs/specs-atmega2560
COLLECT_GCC=E:ATMEL7.0toolchainavr8avr8-gnu-toolchainbinavr-gcc.exe
Target: avr
Configured with: /home/toolsbuild/workspace/avr8-gnu-toolchain/src/gcc/configure LDFLAGS=-L/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs/lib CPPFLAGS= --target=avr --host=i686-w64-mingw32 --build=x86_64-pc-linux-gnu --prefix=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86 --libdir=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86/lib --enable-languages=c,c++ --with-dwarf2 --enable-doc --disable-shared --disable-libada --disable-libssp --disable-nls --with-avrlibc=yes --with-mpfr=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --with-gmp=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --with-mpc=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --enable-win32-registry=avrtoolchain --with-pkgversion=AVR_8_bit_GNU_Toolchain_3.6.2_1778 --with-bugurl=http://www.microchip.com
Thread model: single
gcc version 5.4.0 (AVR_8_bit_GNU_Toolchain_3.6.2_1778) 
COLLECT_GCC_OPTIONS='-funsigned-char' '-funsigned-bitfields' '-D' 'NDEBUG' '-I' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300include' '-O3' '-ffunction-sections' '-fdata-sections' '-fpack-struct' '-fshort-enums' '-mrelax' '-Wall' '-Wextra' '-Wundef'  '-B' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300gccdevatmega2560' '-c' '-std=gnu99' '-v' '-MD' '-MP' '-MF' 'source/IO.d' '-MT' 'source/IO.d' '-MT' 'source/IO.o' '-o' 'source/IO.o' '-specs=device-specs/specs-atmega2560' '-mmcu=avr6'
e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../libexec/gcc/avr/5.4.0/cc1.exe -quiet -v -I E:ATMEL7.0PacksatmelATmega_DFP1.3.300include -imultilib avr6 -iprefix e:atmel7.0toolchainavr8avr8-gnu-toolchainbin../lib/gcc/avr/5.4.0/ -MD source/IO.d -MF source/IO.d -MP -MT source/IO.d -MT source/IO.o -D__AVR_ATmega2560__ -D__AVR_DEVICE_NAME__=atmega2560 -D__AVR_DEV_LIB_NAME__=m2560 -D NDEBUG ../source/IO.c -mn-flash=4 -mno-skip-bug -quiet -dumpbase IO.c -mrelax -mmcu=avr6 -auxbase-strip source/IO.o -O3 -Wall -Wextra -Wundef -std=gnu99 -version -funsigned-char -funsigned-bitfields -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -o C:UsersgothiAppDataLocalTempcc9EwEFa.s
GNU C99 (AVR_8_bit_GNU_Toolchain_3.6.2_1778) version 5.4.0 (avr)
compiled by GNU C version 4.7.4, GMP version 5.0.2, MPFR version 3.0.0, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "e:atmel7.0toolchainavr8avr8-gnu-toolchainbin../lib/gcc/avr/5.4.0/../../../../avr/sys-include"
ignoring duplicate directory "e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/lib/gcc/../../lib/gcc/avr/5.4.0/include"
ignoring duplicate directory "e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/lib/gcc/../../lib/gcc/avr/5.4.0/include-fixed"
ignoring nonexistent directory "e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/lib/gcc/../../lib/gcc/avr/5.4.0/../../../../avr/sys-include"
ignoring duplicate directory "e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/lib/gcc/../../lib/gcc/avr/5.4.0/../../../../avr/include"
#include "..." search starts here:
#include <...> search starts here:
E:ATMEL7.0PacksatmelATmega_DFP1.3.300include
e:atmel7.0toolchainavr8avr8-gnu-toolchainbin../lib/gcc/avr/5.4.0/include
e:atmel7.0toolchainavr8avr8-gnu-toolchainbin../lib/gcc/avr/5.4.0/include-fixed
e:atmel7.0toolchainavr8avr8-gnu-toolchainbin../lib/gcc/avr/5.4.0/../../../../avr/include
End of search list.
GNU C99 (AVR_8_bit_GNU_Toolchain_3.6.2_1778) version 5.4.0 (avr)
compiled by GNU C version 4.7.4, GMP version 5.0.2, MPFR version 3.0.0, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 7a32dfd92aeb38c911f2be52b5ef5d52
COLLECT_GCC_OPTIONS='-funsigned-char' '-funsigned-bitfields' '-D' 'NDEBUG' '-I' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300include' '-O3' '-ffunction-sections' '-fdata-sections' '-fpack-struct' '-fshort-enums' '-mrelax' '-Wall' '-Wextra' '-Wundef'  '-B' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300gccdevatmega2560' '-c' '-std=gnu99' '-v' '-MD' '-MP' '-MF' 'source/IO.d' '-MT' 'source/IO.d' '-MT' 'source/IO.o' '-o' 'source/IO.o' '-specs=device-specs/specs-atmega2560' '-mmcu=avr6'
e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/as.exe -mmcu=avr6 --mlink-relax -mno-skip-bug -o source/IO.o C:UsersgothiAppDataLocalTempcc9EwEFa.s
COMPILER_PATH=E:/ATMEL/7.0/Packs/atmel/ATmega_DFP/1.3.300/gcc/dev/atmega2560/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../libexec/gcc/avr/5.4.0/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../libexec/gcc/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/
LIBRARY_PATH=E:/ATMEL/7.0/Packs/atmel/ATmega_DFP/1.3.300/gcc/dev/atmega2560/avr6/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr6/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr6/;E:/ATMEL/7.0/Packs/atmel/ATmega_DFP/1.3.300/gcc/dev/atmega2560/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/
COLLECT_GCC_OPTIONS='-funsigned-char' '-funsigned-bitfields' '-D' 'NDEBUG' '-I' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300include' '-O3' '-ffunction-sections' '-fdata-sections' '-fpack-struct' '-fshort-enums' '-mrelax' '-Wall' '-Wextra' '-Wundef'  '-B' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300gccdevatmega2560' '-c' '-std=gnu99' '-v' '-MD' '-MP' '-MF' 'source/IO.d' '-MT' 'source/IO.d' '-MT' 'source/IO.o' '-o' 'source/IO.o' '-specs=device-specs/specs-atmega2560' '-mmcu=avr6'
E:ATMEL7.0toolchainavr8avr8-gnu-toolchainbinavr-ar.exe: creating libATMEGA2560.a
C:WindowsSystem32xcopy /Y "C:UsersgothiDocumentsAtmel Studio7.0DroneATMEGA2560headers*.h" "C:UsersgothiDocumentsAtmel Studio7.0DroneATMEGA2560Releaseheaders*.h" 
C:WindowsSystem32xcopy /Y "C:UsersgothiDocumentsAtmel Studio7.0DroneATMEGA2560*.h" "C:UsersUSERDocumentsAtmel Studio7.0DroneATMEGA2560Release*.h" 
C:UsersgothiDocumentsAtmel Studio7.0DroneATMEGA2560headersIO.h
1 File(s) copied
C:UsersgothiDocumentsAtmel Studio7.0DroneATMEGA2560ATMEGA2560.h
1 File(s) copied
------ Build started: Project: Drone, Configuration: Release AVR ------
Shell Utils Path E:ATMEL7.0shellUtils
E:ATMEL7.0shellUtilsmake.exe all 
Using built-in specs.
Reading specs from E:/ATMEL/7.0/Packs/atmel/ATmega_DFP/1.3.300/gcc/dev/atmega2560/device-specs/specs-atmega2560
COLLECT_GCC=E:ATMEL7.0toolchainavr8avr8-gnu-toolchainbinavr-gcc.exe
Target: avr
Configured with: /home/toolsbuild/workspace/avr8-gnu-toolchain/src/gcc/configure LDFLAGS=-L/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs/lib CPPFLAGS= --target=avr --host=i686-w64-mingw32 --build=x86_64-pc-linux-gnu --prefix=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86 --libdir=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86/lib --enable-languages=c,c++ --with-dwarf2 --enable-doc --disable-shared --disable-libada --disable-libssp --disable-nls --with-avrlibc=yes --with-mpfr=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --with-gmp=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --with-mpc=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --enable-win32-registry=avrtoolchain --with-pkgversion=AVR_8_bit_GNU_Toolchain_3.6.2_1778 --with-bugurl=http://www.microchip.com
Thread model: single
gcc version 5.4.0 (AVR_8_bit_GNU_Toolchain_3.6.2_1778) 
COLLECT_GCC_OPTIONS='-funsigned-char' '-funsigned-bitfields' '-D' 'NDEBUG' '-I' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300include' '-I' '../../ATMEGA2560/Release/headers' '-I' '../../ATMEGA2560/Release' '-O3' '-ffunction-sections' '-fdata-sections' '-fpack-struct' '-fshort-enums' '-mrelax' '-Wall' '-Wextra' '-Wundef'  '-B' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300gccdevatmega2560' '-c' '-std=gnu99' '-v' '-MD' '-MP' '-MF' 'main.d' '-MT' 'main.d' '-MT' 'main.o' '-o' 'main.o' '-specs=device-specs/specs-atmega2560' '-mmcu=avr6'
e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../libexec/gcc/avr/5.4.0/cc1.exe -quiet -v -I E:ATMEL7.0PacksatmelATmega_DFP1.3.300include -I ../../ATMEGA2560/Release/headers -I ../../ATMEGA2560/Release -imultilib avr6 -iprefix e:atmel7.0toolchainavr8avr8-gnu-toolchainbin../lib/gcc/avr/5.4.0/ -MD main.d -MF main.d -MP -MT main.d -MT main.o -D__AVR_ATmega2560__ -D__AVR_DEVICE_NAME__=atmega2560 -D__AVR_DEV_LIB_NAME__=m2560 -D NDEBUG .././main.c -mn-flash=4 -mno-skip-bug -quiet -dumpbase main.c -mrelax -mmcu=avr6 -auxbase-strip main.o -O3 -Wall -Wextra -Wundef -std=gnu99 -version -funsigned-char -funsigned-bitfields -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -o C:UsersgothiAppDataLocalTempccvaSiXr.s
GNU C99 (AVR_8_bit_GNU_Toolchain_3.6.2_1778) version 5.4.0 (avr)
compiled by GNU C version 4.7.4, GMP version 5.0.2, MPFR version 3.0.0, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "e:atmel7.0toolchainavr8avr8-gnu-toolchainbin../lib/gcc/avr/5.4.0/../../../../avr/sys-include"
ignoring duplicate directory "e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/lib/gcc/../../lib/gcc/avr/5.4.0/include"
ignoring duplicate directory "e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/lib/gcc/../../lib/gcc/avr/5.4.0/include-fixed"
ignoring nonexistent directory "e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/lib/gcc/../../lib/gcc/avr/5.4.0/../../../../avr/sys-include"
ignoring duplicate directory "e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/lib/gcc/../../lib/gcc/avr/5.4.0/../../../../avr/include"
#include "..." search starts here:
#include <...> search starts here:
E:ATMEL7.0PacksatmelATmega_DFP1.3.300include
../../ATMEGA2560/Release/headers
../../ATMEGA2560/Release
e:atmel7.0toolchainavr8avr8-gnu-toolchainbin../lib/gcc/avr/5.4.0/include
e:atmel7.0toolchainavr8avr8-gnu-toolchainbin../lib/gcc/avr/5.4.0/include-fixed
e:atmel7.0toolchainavr8avr8-gnu-toolchainbin../lib/gcc/avr/5.4.0/../../../../avr/include
End of search list.
GNU C99 (AVR_8_bit_GNU_Toolchain_3.6.2_1778) version 5.4.0 (avr)
compiled by GNU C version 4.7.4, GMP version 5.0.2, MPFR version 3.0.0, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 7a32dfd92aeb38c911f2be52b5ef5d52
COLLECT_GCC_OPTIONS='-funsigned-char' '-funsigned-bitfields' '-D' 'NDEBUG' '-I' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300include' '-I' '../../ATMEGA2560/Release/headers' '-I' '../../ATMEGA2560/Release' '-O3' '-ffunction-sections' '-fdata-sections' '-fpack-struct' '-fshort-enums' '-mrelax' '-Wall' '-Wextra' '-Wundef'  '-B' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300gccdevatmega2560' '-c' '-std=gnu99' '-v' '-MD' '-MP' '-MF' 'main.d' '-MT' 'main.d' '-MT' 'main.o' '-o' 'main.o' '-specs=device-specs/specs-atmega2560' '-mmcu=avr6'
e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/as.exe -mmcu=avr6 --mlink-relax -mno-skip-bug -o main.o C:UsersgothiAppDataLocalTempccvaSiXr.s
COMPILER_PATH=E:/ATMEL/7.0/Packs/atmel/ATmega_DFP/1.3.300/gcc/dev/atmega2560/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../libexec/gcc/avr/5.4.0/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../libexec/gcc/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/
LIBRARY_PATH=E:/ATMEL/7.0/Packs/atmel/ATmega_DFP/1.3.300/gcc/dev/atmega2560/avr6/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/avr6/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr6/;E:/ATMEL/7.0/Packs/atmel/ATmega_DFP/1.3.300/gcc/dev/atmega2560/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/;e:/atmel/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/
COLLECT_GCC_OPTIONS='-funsigned-char' '-funsigned-bitfields' '-D' 'NDEBUG' '-I' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300include' '-I' '../../ATMEGA2560/Release/headers' '-I' '../../ATMEGA2560/Release' '-O3' '-ffunction-sections' '-fdata-sections' '-fpack-struct' '-fshort-enums' '-mrelax' '-Wall' '-Wextra' '-Wundef'  '-B' 'E:ATMEL7.0PacksatmelATmega_DFP1.3.300gccdevatmega2560' '-c' '-std=gnu99' '-v' '-MD' '-MP' '-MF' 'main.d' '-MT' 'main.d' '-MT' 'main.o' '-o' 'main.o' '-specs=device-specs/specs-atmega2560' '-mmcu=avr6'
main.o: In function `main':
C:UsersUSERDocumentsAtmel Studio7.0DroneDroneReleasemain.c(1,1): error: undefined reference to `function_1'
collect2.exe(0,0): error: ld returned 1 exit status
make: *** [Drone.elf] Error 1
C:UsersUSERDocumentsAtmel Studio7.0DroneDroneReleaseMakefile(106,1): error: recipe for target 'Drone.elf' failed
Done building project "Drone.cproj" -- FAILED.
Build FAILED.
========== Build: 1 succeeded or up-to-date, 1 failed, 0 skipped ==========

也许这只是一个拼写错误,但你说你的静态库有结构:

ATMEGA2560
|-headers
| |-IO.h
|-source
| |-IO.c
|-ATMEGA2560.h

但你的参考是指向一个有Release文件夹的目录,比如

ATMEGA2560
|-Release
| |-headers
| | |-IO.h
| |-source
| | |-IO.c
| |-ATMEGA2560.h

此外,还有avr-libc库和io.h中的avr/io.h。我过去在Atmel Studio中遇到过一些问题,无法区分adc.h和adc.h等文件。试着将ATMEGA2560标头io.h重命名为其他文件(如果可以的话(,也许这会解决你的问题。

相关内容

  • 没有找到相关文章

最新更新