I'm trying to export the symbol of a macro outside a module but the compiler exit with: "Error[34]: May not be redefined"
I'm splitting a program written in IAR assembler in several modules as it was written as a unique big chunk of code. I come across several MACROs supposed to be used as a fast inline function and I'm trying to put them in their related modules and import them as symbols where they are needed. The problem arise when I only add the name/symbol of the macro to the public ones of the module hosting them: even without importing it, the compiler exits with "Error[34]: May not be redefined". If possible I would prefer to keep them whitin the related module. Can I achieve this? Or I'm getting it the wrong way?
MODULE MY_MODULE
PUBLIC GET_VALUE_XYZ
#include "msp430.h"
#include "defines.s43"
RSEG CODE
GET_VALUE_XYZ MACRO parameter_1
<...cut...>
ENDM
END
Macros are not functions in a normal sense, they provide short-hand notations for common instruction sequences (somewhat like #define macros in C). Thus, macros can only be referred to in modules where the definition is visible. It is not possble to export them to other modules using the PUBLIC keyword.
It is possible to separate the macro definitions from the rest of the code and put them in separate files but then you need to include these files using the #include directive.
Related
Problem Solved!!! See below for solution
I was about to post this question and decided to check the web one more time. This site https://www.freepascal.org/docs-html/prog/progsu40.html
has this statement: The {$I filename} or {$INCLUDE filename} directive tells the compiler to read further statements from the file filename. The statements read there will be inserted as if they occurred in the current file.
This is exactly what I want to do with Arduino. How do I do it?
My Skill Set:
Writing code since 1967. Yes, I survived Y2K, which was a real thing; so I'm not new to programming/debugging. Mainframes and PC's. Very solid COBOL and SAS skills. Good skills with Borland/Lazarus Object Pascal. Weak C/C++ skills.
Background:
I have two working Arduino programs that are used on a model railroad. Prog1 uses infrared sensors to light LEDs that indicate the position of a train in a tunnel. I built the IRSensor class to handle a single sensor. Prog2 uses push-buttons to set a route through several track switches. Each track switch is set via a servo. I extended the Servo class to TOServo, which encapsulate most of the commonality in each track switch.
Now I'm working on a different model railroad and need merge Prog1 and Prog2 into a single program. Building Prog3 via copy/paste from programs 1 & 2 has proved unwieldy.
Problem:
How do I tell the Arduino pre-processor/compiler to "insert filename here; do not compile, pre-compile, or otherwise process the filename unless it is wrapped around the file asking for the insertion"?
What I've tried:
I built Prog3 by separating the code for Prog2 into 3 sections -- Main program storage & code and 2 include statements (Storage definitions and executable code for TOServo). These include statements pull in code that define or access an array of TOServo. I've used several suffixes (.h/.ino and .h/.cpp and .c/.c), and they all generate 'not declared in this scope' errors.
Finally:
Thanks for your help.
SOLUTION
My .ino file had grown large & unwieldy. The 'solution' was to move a large segment of code and matching declarations to external .h/.cpp files, and to access those files via #include statements. The program would not compile (undefined variables); they were, in fact, defined but the compiler couldn't find them. After many attempts to fix or rearrange the code, finally two things dawned on me.
1)The Arduino pre-compiler changes (rearranges?) my code so that C++ and the Arduino CPU can work together. This means that the code I see is not always the code the compiler sees.
2)My .h/.cpp files define and manage an array of servo objects. I could convert those files into an object that I access from the main .ino file.
So I've solved my problem. Thanks to all those who have posted in many forums/sites, especially to Tarick Welling who stayed with me to the end.
I have written a library called redux-async-action-reducer. I have written it in typescript. I want to add flow definition to it.
Is there any way I can keep it along with my library rather than creating a separate and putting it in flow-typed?
Something like d.ts for flow defintion files?
You could ship your library with a .js.flow file alongside your package entry point. In your case (since your package entry point is dist/index.js you would create a file at dist/index.js.flow.
Flow will then treat this like a normal source file. You'll have to remember to put // #flow at the top. You can either write functions and classes with stubbed out implementations, or use declare (e.g. declare export function foo(x: string): string;, similar for class).
Note that this will actually be different than a library definition file -- Flow will treat it like source code.
Flow-typed is the preferred way to distribute libdefs. Using .js.flow files can lead to issues when Flow makes breaking changes between versions. However, since you will be distributing a hand-curated interface, rather than shipping your entire library source as .js.flow files, that issue will be mitigated.
I faced a situation that I need some tables to be filled in one source file (for example fill.cu) and then be used in different kernels in different source files.
I tried declaring a pointer __device__ float *myTable; as 'extern' in fill.h header file and adding that to others.cpp and defining that pointer in fill.cu and allocate and fill it there.
This way, I got linker error indicating that myTable has been already defined in fill.cpp.
After many unsuccessful try, I decided to put all kernels that need this table in same source file, this way everything works fine until I added an cudaMalloc in main function before allocating my table in fill.cpp.
This way I noticed that table values and data allocated in main are overlapped and using cuda debugging tools of MS visual studio 2015, I found that 2 allocated pointer are same!!!
Please advice how to declare a global pointer in cuda without conflict.
The traditional CUDA linkage model requires that all device symbols, textures, functions, etc. are defined and used within the scope of the same translation unit. It sounds like your code structure is violating this requirement.
You have two choices:
Continue to the same code structure, but provide wrapper functions which your main can call to perform operations on statically declared device variables, rather than directly manipulating device symbols with the CUDA API from other code.
Use separate compilation. Here, you define the device symbol you want to access in exactly one file and declare the same symbol as externeverywhere else you need to use that symbol. You must explicitly use several nvcc options to compile your device code and use a separate device code linking stage.
Both approaches are well documented.
I'm trying to create a Qt shared library that wraps a lower level C library, meaning that I don't want that C library's header file to be accessed by the calling code that links to the library.
I'm following the steps here, which seem to be straightforward. I've constructed a SUBDIRS project in QtCreator. The library project builds fine, all classes and C functions are marked with the macro that expands to Q_DECL_EXPORT. The library defines a some headers that I want to include in the app project. The problem here is that when I include one of those headers, the chain is followed down to the C library header that is included, and at which point the application project fails to build since it can't find that header.
Qt's documentation specifically points out this issue, but is kind of vague about how to solve it.
#include <footronics/device.h>
class MyDevice {
private:
FOOTRONICS_DEVICE_HANDLE handle;
};
When deploying the library, there should be no dependency to the internal headers footronics/device.h or ui_widget.h.
So, how can I avoid the headers that I'm including from the library, from implicitly including the headers from the C library that I'm wrapping?
If you only use pointers or references to classes of the shared library you can use Forward Declarations:
class FooTronicsDevice;
class MyDevice {
private:
FooTronicsDevice* _device;
}
The compiler doesn't need to know the structure of the class in order to define a pointer (or a reference).
If this isn't possible, you can use the Pointer to Implementation idiom which is suggested in the Qt Documentation.
This basically means you separate the implementation from your public interface.
I want to analyze a file from a large project to create a Program Dependence Graph using Frama-C, but keep getting odd errors such as:
/usr/include/bits/fcntl-linux.h:305:[kernel] user error: Length of array is zero. This extension is unsupported
If I try to use the libc implementation provided by frama-c, compilation fails due to missing headers such as sys/file.h.
I am trying to analyze files from the Lynx project, specifically the file in src/WWW/Library/Implementation/HTTP.c, using GCC version 4.8.1
What I really need is to be able to generate a PDG for this source file (which of course has various dependencies) but I think if I could get even a somewhat incomplete graph by skipping over undefined functions, that would be a great first step.
You need to provide your own "file.h" file in a directory "sys" placed anywhere in the path GCC searches when pre-processing for Frama-C.
For reference, here is the implementation of sys/file.h on another system. You may also be interested in this other StackOverflow question about sys/file.h.
For Frama-C's value analysis, assigns clauses alongside the prototypes go a long way:
/*# assigns *f \from ui, s, *fo; */
void finit(struct file *f, u_int ui, short s, void *p, struct fileops *fo);
Note that I have no idea what function finit() does and whether the above is a correct assigns clause for it. In fact, this is the whole point: neither does Frama-C out of the box, and since this lowish-level, lessish-portable system call is used in the code you wish to analyze, someone will have to know. I am afraid it is going to have to be you. On the plus side, you only need to provide the types, macros and function prototypes that the code you wish to analyze uses.