Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--defsym=__rtc_localtime=$(shell powershell [int](Get-Date -UFormat +%s)[0]) not accepted #50

Closed
sschiesser opened this issue May 28, 2021 · 11 comments · Fixed by #51
Closed

Comments

@sschiesser
Copy link

When using the prebuilt visualTeensy 1.0.0.0 example (Win10, 1909), I get the following error message:

[LD] .vsteensy/build/visualTeensyTest.elf c:/progra~2/arduino/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe:--defsym:1: syntax error collect2.exe: error: ld returned 1 exit status make: *** [makefile:236: .vsteensy/build/visualTeensyTest.elf] Error 1 The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'C:/Program Files (x86)/VisualTeensy/make.exe' all -j -Otarget" terminated with exit code: 1.

It looks like ld.exe doesn't like the syntax of the --defsym flag. When replacing the whole $(...) part with 1 (result given by the powershell), it doesn't complain at all.

Is that a Windows or a visualTeensy issue? Thanks!

@luni64
Copy link
Owner

luni64 commented May 28, 2021

This is interesting, I assume you are sure that you didn't accidentally changed the makefile? Can you remove the @ before the linker command in the makefile and recompile so that I can see the actual link command?

image

@sschiesser
Copy link
Author

sschiesser commented May 28, 2021 via email

@luni64
Copy link
Owner

luni64 commented May 29, 2021

Looks like you answered by eMail which seems to have thrown off the attached screenshots. Would it be possible to repost your answer directly in GitHub?

I can only guess that something in your configuration is different, I got a few complaints about weird things happening with the scripting recently. I assume that something in vsCode, Powershell or Windows changed but I wasn't able to reproduce it so far. I'm highly interested in fixing this but I need to be able to reproduce the effect first.

Some questions which might help:

  • Do you have any special settings in vsCode? Maybe a non standard shell?
  • Can you post your vsCode user / workspace setting files (xxx\AppData\Roaming\Code\User\setup.json and ( if exist) yourProject\.vscode\settings.json)
  • Your makefile would also be interesting

@sschiesser
Copy link
Author

Updated my previous comment in github to see pictures... now they appear as links (!)

My setup.json look pretty simple:

{
    "editor.formatOnSave": true,
    "[cpp]": {
        "editor.defaultFormatter": "ms-vscode.cpptools"
    },
    "editor.tabSize": 2
}

My project has a tasks.json and a c_cpp_properties.json but no settings.json

Makefile:

#******************************************************************************
# Generated by VisualTeensy (https://github.com/luni64/VisualTeensy)
#
# Board              Teensy 3.6
# USB Type           Serial
# CPU Speed          180 MHz
# Optimize           Faster
# Keyboard Layout    US English
#
# 29 May 2021 11:07
#******************************************************************************
SHELL            := cmd.exe
export SHELL

TARGET_NAME      := newProject
BOARD_ID         := TEENSY36

MCU              := mk66fx1m0

LIBS_SHARED_BASE := C:\PROGRA~2\Arduino\hardware\teensy\avr\LIBRAR~1
LIBS_SHARED      := 

LIBS_LOCAL_BASE  := lib
LIBS_LOCAL       := 

CORE_BASE        := C:\PROGRA~2\Arduino\hardware\teensy\avr\cores\teensy3
GCC_BASE         := C:\PROGRA~2\Arduino\hardware\tools\arm\bin
UPL_PJRC_B       := C:\PROGRA~2\Arduino\hardware\tools
UPL_TYCMD_B      := C:\PROGRA~2\Arduino\hardware\tools

#******************************************************************************
# Flags and Defines
#******************************************************************************
FLAGS_CPU   := -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant
FLAGS_OPT   := -O2
FLAGS_COM   := -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD
FLAGS_LSP   := 

FLAGS_CPP   := -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti
FLAGS_C     := 
FLAGS_S     := -x assembler-with-cpp
FLAGS_LD    := -Wl,--print-memory-usage,--gc-sections,--relax,--defsym=__rtc_localtime=$(shell powershell [int](Get-Date -UFormat +%s)[0]) -T$(CORE_BASE)/mk66fx1m0.ld

LIBS        := -larm_cortexM4lf_math -lm -lstdc++

DEFINES     := -D__MK66FX1M0__ -DTEENSYDUINO=154 -DARDUINO_TEENSY36 -DARDUINO=10813
DEFINES     += -DF_CPU=180000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH

CPP_FLAGS   := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_CPP)
C_FLAGS     := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_C)
S_FLAGS     := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_S)
LD_FLAGS    := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_LSP) $(FLAGS_LD)
AR_FLAGS    := rcs
NM_FLAGS    := --numeric-sort --defined-only --demangle --print-size

#******************************************************************************
# Colors
#******************************************************************************
COL_CORE    := �[38;2;187;206;251m
COL_LIB     := �[38;2;206;244;253m
COL_SRC     := �[38;2;100;149;237m
COL_LINK    := �[38;2;255;255;202m
COL_ERR     := �[38;2;255;159;159m
COL_OK      := �[38;2;179;255;179m
COL_RESET   := �[0m

#******************************************************************************
# Folders and Files
#******************************************************************************
USR_SRC         := src
LIB_SRC         := lib
CORE_SRC        := $(CORE_BASE)

BIN             := .vsteensy/build
USR_BIN         := $(BIN)/src
CORE_BIN        := $(BIN)/core
LIB_BIN         := $(BIN)/lib
CORE_LIB        := $(BIN)/core.a
TARGET_HEX      := $(BIN)/$(TARGET_NAME).hex
TARGET_ELF      := $(BIN)/$(TARGET_NAME).elf
TARGET_LST      := $(BIN)/$(TARGET_NAME).lst
TARGET_SYM      := $(BIN)/$(TARGET_NAME).sym

#******************************************************************************
# BINARIES
#******************************************************************************
CC              := $(GCC_BASE)/arm-none-eabi-gcc
CXX             := $(GCC_BASE)/arm-none-eabi-g++
AR              := $(GCC_BASE)/arm-none-eabi-gcc-ar
NM              := $(GCC_BASE)/arm-none-eabi-gcc-nm
SIZE            := $(GCC_BASE)/arm-none-eabi-size
OBJDUMP         := $(GCC_BASE)/arm-none-eabi-objdump
OBJCOPY         := $(GCC_BASE)/arm-none-eabi-objcopy
UPL_PJRC        := "$(UPL_PJRC_B)/teensy_post_compile" -test -file=$(TARGET_NAME) -path=$(BIN) -tools="$(UPL_PJRC_B)" -board=$(BOARD_ID) -reboot
UPL_TYCMD       := $(UPL_TYCMD_B)/tyCommanderC upload $(TARGET_HEX) --autostart --wait --multi
UPL_CLICMD      := $(UPL_CLICMD_B)/teensy_loader_cli -mmcu=$(MCU) -v $(TARGET_HEX)
UPL_JLINK       := $(UPL_JLINK_B)/jlink -commanderscript .vsteensy/flash.jlink

#******************************************************************************
# Source and Include Files
#******************************************************************************
# Recursively create list of source and object files in USR_SRC and CORE_SRC
# and corresponding subdirectories.
# The function rwildcard is taken from http://stackoverflow.com/a/12959694)

rwildcard =$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))

#User Sources -----------------------------------------------------------------
USR_C_FILES     := $(call rwildcard,$(USR_SRC)/,*.c)
USR_CPP_FILES   := $(call rwildcard,$(USR_SRC)/,*.cpp)
USR_S_FILES     := $(call rwildcard,$(USR_SRC)/,*.S)
USR_OBJ         := $(USR_S_FILES:$(USR_SRC)/%.S=$(USR_BIN)/%.o) $(USR_C_FILES:$(USR_SRC)/%.c=$(USR_BIN)/%.o) $(USR_CPP_FILES:$(USR_SRC)/%.cpp=$(USR_BIN)/%.o)

# Core library sources --------------------------------------------------------
CORE_CPP_FILES  := $(call rwildcard,$(CORE_SRC)/,*.cpp)
CORE_C_FILES    := $(call rwildcard,$(CORE_SRC)/,*.c)
CORE_S_FILES    := $(call rwildcard,$(CORE_SRC)/,*.S)
CORE_OBJ        := $(CORE_S_FILES:$(CORE_SRC)/%.S=$(CORE_BIN)/%.o) $(CORE_C_FILES:$(CORE_SRC)/%.c=$(CORE_BIN)/%.o) $(CORE_CPP_FILES:$(CORE_SRC)/%.cpp=$(CORE_BIN)/%.o)

# User library sources (see https://github.com/arduino/arduino/wiki/arduino-ide-1.5:-library-specification)
LIB_DIRS_SHARED := $(foreach d, $(LIBS_SHARED), $(LIBS_SHARED_BASE)/$d/ $(LIBS_SHARED_BASE)/$d/utility/)      # base and /utility
LIB_DIRS_SHARED += $(foreach d, $(LIBS_SHARED), $(LIBS_SHARED_BASE)/$d/src/ $(dir $(call rwildcard,$(LIBS_SHARED_BASE)/$d/src/,*/.)))                          # src and all subdirs of base

LIB_DIRS_LOCAL  := $(foreach d, $(LIBS_LOCAL), $(LIBS_LOCAL_BASE)/$d/ $(LIBS_LOCAL_BASE)/$d/utility/ )        # base and /utility
LIB_DIRS_LOCAL  += $(foreach d, $(LIBS_LOCAL), $(LIBS_LOCAL_BASE)/$d/src/ $(dir $(call rwildcard,$(LIBS_LOCAL_BASE)/$d/src/,*/.)))                          # src and all subdirs of base

LIB_CPP_SHARED  := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.cpp))
LIB_C_SHARED    := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.c))
LIB_S_SHARED    := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.S))

LIB_CPP_LOCAL   := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.cpp))
LIB_C_LOCAL     := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.c))
LIB_S_LOCAL     := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.S))

LIB_OBJ         := $(LIB_CPP_SHARED:$(LIBS_SHARED_BASE)/%.cpp=$(LIB_BIN)/%.o)  $(LIB_CPP_LOCAL:$(LIBS_LOCAL_BASE)/%.cpp=$(LIB_BIN)/%.o)
LIB_OBJ         += $(LIB_C_SHARED:$(LIBS_SHARED_BASE)/%.c=$(LIB_BIN)/%.o)  $(LIB_C_LOCAL:$(LIBS_LOCAL_BASE)/%.c=$(LIB_BIN)/%.o)
LIB_OBJ         += $(LIB_S_SHARED:$(LIBS_SHARED_BASE)/%.S=$(LIB_BIN)/%.o)  $(LIB_S_LOCAL:$(LIBS_LOCAL_BASE)/%.S=$(LIB_BIN)/%.o)

# Includes -------------------------------------------------------------
INCLUDE         := -I./$(USR_SRC) -I$(CORE_SRC)
INCLUDE         += $(foreach d, $(LIB_DIRS_SHARED), -I$d)
INCLUDE         += $(foreach d, $(LIB_DIRS_LOCAL), -I$d)

# Generate directories --------------------------------------------------------
DIRECTORIES     :=  $(sort $(dir $(CORE_OBJ) $(USR_OBJ) $(LIB_OBJ)))
generateDirs    := $(foreach d, $(DIRECTORIES), $(shell if not exist "$d" mkdir "$d"))

#$(info dirs: $(DIRECTORIES))

#******************************************************************************
# Rules:
#******************************************************************************

.PHONY: directories all rebuild upload uploadTy uploadCLI clean cleanUser cleanCore

all:  $(TARGET_LST) $(TARGET_SYM) $(TARGET_HEX)

rebuild: cleanUser all

clean: cleanUser cleanCore cleanLib
	@echo $(COL_OK)cleaning done$(COL_RESET)

upload: all
	@$(UPL_PJRC)

uploadTy: all
	@$(UPL_TYCMD)

uploadCLI: all
	@$(UPL_CLICMD)

uploadJLink: all
	@$(UPL_JLINK)

# Core library ----------------------------------------------------------------
$(CORE_BIN)/%.o: $(CORE_SRC)/%.S
	@echo $(COL_CORE)CORE [ASM] $(notdir $<) $(COL_ERR)
	@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<

$(CORE_BIN)/%.o: $(CORE_SRC)/%.c
	@echo $(COL_CORE)CORE [CC]  $(notdir $<) $(COL_ERR)
	@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<

$(CORE_BIN)/%.o: $(CORE_SRC)/%.cpp
	@echo $(COL_CORE)CORE [CPP] $(notdir $<) $(COL_ERR)
	@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $@ -c $<

$(CORE_LIB) : $(CORE_OBJ)
	@echo $(COL_LINK)CORE [AR] $@ $(COL_ERR)
	@$(AR) $(AR_FLAGS) $@ $^
	@echo $(COL_OK)Teensy core built successfully &&echo.

# Shared Libraries ------------------------------------------------------------
$(LIB_BIN)/%.o: $(LIBS_SHARED_BASE)/%.S
	@echo $(COL_LIB)LIB [ASM] $(notdir $<) $(COL_ERR)
	@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<

$(LIB_BIN)/%.o: $(LIBS_SHARED_BASE)/%.cpp
	@echo $(COL_LIB)LIB [CPP] $(notdir $<) $(COL_ERR)
	@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $@ -c $<

$(LIB_BIN)/%.o: $(LIBS_SHARED_BASE)/%.c
	@echo $(COL_LIB)LIB [CC]  $(notdir $<) $(COL_ERR)
	@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<

# Local Libraries -------------------------------------------------------------
$(LIB_BIN)/%.o: $(LIBS_LOCAL_BASE)/%.S
	@echo $(COL_LIB)LIB [ASM] $(notdir $<) $(COL_ERR)
	@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<

$(LIB_BIN)/%.o: $(LIBS_LOCAL_BASE)/%.cpp
	@echo $(COL_LIB)LIB [CPP] $(notdir $<) $(COL_ERR)
	@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $@ -c $<

$(LIB_BIN)/%.o: $(LIBS_LOCAL_BASE)/%.c
	@echo $(COL_LIB)LIB [CC]  $(notdir $<) $(COL_ERR)
	@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<

# Handle user sources ---------------------------------------------------------
$(USR_BIN)/%.o: $(USR_SRC)/%.S
	@echo $(COL_SRC)USER [ASM] $< $(COL_ERR)
	@"$(CC)" $(S_FLAGS) $(INCLUDE) -o "$@" -c $<

$(USR_BIN)/%.o: $(USR_SRC)/%.c
	@echo $(COL_SRC)USER [CC]  $(notdir $<) $(COL_ERR)
	@"$(CC)" $(C_FLAGS) $(INCLUDE) -o "$@" -c $<

$(USR_BIN)/%.o: $(USR_SRC)/%.cpp
	@echo $(COL_SRC)USER [CPP] $(notdir $<) $(COL_ERR)
	@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o "$@" -c $<

# Linking ---------------------------------------------------------------------
$(TARGET_ELF): $(CORE_LIB) $(LIB_OBJ) $(USR_OBJ)
	@echo $(COL_LINK)
	@echo [LD]  $@ $(COL_ERR)
	@$(CC) $(LD_FLAGS) -o "$@" $(USR_OBJ) $(LIB_OBJ) $(CORE_LIB) $(LIBS)
	@echo $(COL_OK)User code built and linked to libraries &&echo.

%.lst: %.elf
	@echo [LST] $@
	@$(OBJDUMP) -d -S --demangle --no-show-raw-insn "$<" > "$@"
	@echo $(COL_OK)Sucessfully built project$(COL_RESET) &&echo.

%.sym: %.elf
	@echo [SYM] $@
	@$(NM) $(NM_FLAGS) "$<" > "$@"

%.hex: %.elf
	@echo $(COL_LINK)[HEX] $@
	@$(OBJCOPY) -O ihex -R.eeprom "$<" "$@"

# Cleaning --------------------------------------------------------------------
cleanUser:
	@echo $(COL_LINK)Cleaning user binaries...$(COL_RESET)
	@if exist $(USR_BIN) rd /s/q "$(USR_BIN)"
	@if exist "$(TARGET_LST)" del $(subst /,\,$(TARGET_LST))

cleanCore:
	@echo $(COL_LINK)Cleaning core binaries...$(COL_RESET)
	@if exist $(CORE_BIN) rd /s/q "$(CORE_BIN)"
	@if exist $(CORE_LIB) del  $(subst /,\,$(CORE_LIB))

cleanLib:
	@echo $(COL_LINK)Cleaning user library binaries...$(COL_RESET)
	@if exist $(LIB_BIN) rd /s/q "$(LIB_BIN)"

# compiler generated dependency info ------------------------------------------
-include $(CORE_OBJ:.o=.d)
-include $(USR_OBJ:.o=.d)
-include $(LIB_OBJ:.o=.d)

@luni64
Copy link
Owner

luni64 commented May 29, 2021

That all looks OK. I saw that you have the shared libraries folder inside the Arduino folder which is strange (usually it is at ...Documents/arduino/libraries) but this is certainly not the problem.

To isolate the problematic call to get-date I slightly rewrote the makefile. Maybe this gives more info about the underlying problem. Can you replace the FLAGS_LD .... line (around line 45) by the following 3 lines:

TIME_SYM    := $(shell powershell [int](Get-Date -UFormat %s))
$(info TIME_SYM: $(TIME_SYM))
FLAGS_LD    := -Wl,--print-memory-usage,--gc-sections,--relax,--defsym=__rtc_localtime=$(TIME_SYM) -T$(CORE_BASE)/mk66fx1m0.ld

It also looks like your powershell is quite old. In your error message you get:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'C:/Program Files...

If I provoke a linker error I get:

C:\Program Files\PowerShell\7\pwsh.exe -Command...

Maybe updating to a current version helps

@sschiesser
Copy link
Author

Hi

First the rewroten Makefile doesn't look to behave on a different way than before. The terminal gives:
image

Second I noticed that Windows had a powershell version 5.1 (x86) located somewhere in /AppData/Roaming/.... So I updated it to v7.1 (located now in /Program Files/PowerShell and uninstalled v5.1.
Unfortunately, the result is still the same:
image

@luni64
Copy link
Owner

luni64 commented May 31, 2021

Thanks a lot that helped. The issue might be related to the setting of the decimal char. Can you type the following in a powershell terminal (e.g. the standard terminal in vscode)

Get-Date -UFormat %s 

On a PC with e,g, German language setting this gives e.g. 1622464559,36875 (decimal symbol comma) on a PC with englisch settings I get 1622464559.36875 (dot). However, the cast to int doesn't work with the comma.
So, if I type this

[int](Get-Date -UFormat %s)

command into the terminal, I get this error:

Cannot convert value "1622464685,06447" to type "System.Int32". Error: "Input string was not in a correct format."
At line:1 char:1
+ [int](Get-Date -UFormat %s)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastFromStringToInteger

On a PC with a dot as decimal symbol I get the correctly casted result.

Can you check if

Get-Date -UFormat %s

outputs the date with dot or comma as decimal separator on your PC?

BTW: Sorry to bother you with debugging my code....

@sschiesser
Copy link
Author

Weird: I get an int value
image

But my settings on this topic are customized and therefore probably leading to some mistake:

  • Keyboard language: Swiss german
  • Input language: English (Switzerland)
  • Decimal symbol: (dot)
  • Digit grouping symbol: (apostrophe)

...don't know if that helps...

BTW: no problem with helping debugging your code. Thank you to allow me working with teensy in a real IDE ;-)

@luni64
Copy link
Owner

luni64 commented Jun 1, 2021

Weird: I get an int value

Actually it returns a string and it looks like the standard formatting for this string changed between PS versions. Anyway, the following should return an integer (number of seconds since 1970) regardless of the PS version and/or language settings. I tested it with swiss settings and all available combinations of decimal and grouping symbols.

[int][double]::Parse((Get-Date -UFormat %s))

I'll try to compile a new vsTeensy version for testing later today.

@luni64
Copy link
Owner

luni64 commented Jun 4, 2021

Let me know if this works for you

@luni64 luni64 reopened this Jun 4, 2021
@luni64
Copy link
Owner

luni64 commented Aug 23, 2021

fixed in v1.2.0

@luni64 luni64 closed this as completed Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants