in Education by
I have an embedded IoT project that I like to first develop in part by using PC tools such as VisualStudio. My embedded project has only a flash memory for a file system, and I'd like to redirect fopen fread etc. to my own private implementation on Windows. But what I'm encountering is an inability to have my private CRT library take precedence over the built-in CRT (e.g., built-in behavior driven by /MD compiler switch). I have a simple three project solution. Project 1 is a test executable. It has a one line main: int main() { test(); } Project 2 and 3 are static libraries. Project 2 has: #include #include void test() { printf("%s\n", strchr("x", 'x')); } Project 3 has: char * strchr(const char * s, int c) // exact signature of MSVC { return "overridden"; } I expect output to be overridden but instead it is x But if I add this to Project 1: printf("%s\n", strchr("y", 'y')); The output will be overridden overridden First one from test() in library, second from executable main() directly. Any suggestions? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The linker resolves symbols on a first match basis - priority to separately linked .obj files, then .lib files in the order presented to the linker of the command line. So you can normally override a library symbol just be linking your own replacement. I have never tried it with MSVC, and it is a somewhat brutal approach. An alternative solution that does not rely on specific linker behaviour is to use the pre-processor to replace standard symbols with your own alternatives. For example: #if defined _WIN32 #define fopen test_fopen FILE* test_fopen( const char * filename, const char * mode ) ; #endif add the other macros and declarations you need in a header file called testlib.h for example then use a "forced include" (/FI testlib.h in MSVC) to invisibly include the test interface everywhere. Then when built on Windows, all fopen calls will be replaced with test_fopen calling your replacement functions instead.

Related questions

0 votes
    All compilers I could get my hands on agree that this is fine: template auto foo(Check, T...) - ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    I had a program working good (without prompting errors) using references, but I decided to use a pointer-to-pointer array ... that it is there because I have put two flags (cout...
asked Apr 6, 2022 in Education by JackTerrance
0 votes
    In an CRT or LCD monitor, the following three colors are used to form all of the other colors: yellow orange red blue violet green...
asked May 9, 2021 in General by JackTerrance
0 votes
    Replacing the differentiation with D1, D2 in the equation 100 = 20i + 0.05 \frac{di}{dt} + \frac{1}{ ... Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 16, 2021 in Education by JackTerrance
0 votes
    The series combination of the last elements after replacing 1/s and 1/4Ω with 1/(S+4) is? (a) (3s+4) ... Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 16, 2021 in Education by JackTerrance
0 votes
    Determine the admittance parallel combination of the last elements after replacing with (3s+4)/2s(s+4) is? (a) ... for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 16, 2021 in Education by JackTerrance
0 votes
    Which of the following IS NOT one of the advantages associated with a robotics implementation program? (a) Low ... for worker fringe benefits Please answer the above question....
asked Oct 22, 2022 in Education by JackTerrance
0 votes
    Which of the following IS NOT one of the advantages associated with a robotics implementation program? (a) Low ... for worker fringe benefits Please answer the above question....
asked Oct 2, 2022 in Education by JackTerrance
0 votes
    I am working on a very large scale computing library that is using STL heavily. The library is being ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    I want to implement Web sockets for a couple of Web services. How will the stateful HTTP connections impact Blue- ... . Please help. Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    We begin with a computer implemented in single-cycle implementation. When the stages are split by functionality, the stages ... x 10= 1 Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    Comparing the outcomes with the original task requirements a. design b. implementation c. evaluation Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    Comparing the outcomes with the original task requirements a. design b. implementation c. evaluation Select the correct answer from above options...
asked Dec 18, 2021 in Education by JackTerrance
0 votes
    A bag contains 17 tickets, numbered from 1 to 17. A ticket is drawn and then another ticket is drawn without ... may show even numbers. Select the correct answer from above options...
asked Nov 21, 2021 in Education by JackTerrance
...