Skip to content

fix: move tape storage and thread_alloc statics to cppad_lib for DLL … - #256

Open
Yunsen wants to merge 2 commits into
coin-or:mainfrom
Yunsen:refactor/odr-problem-fix
Open

fix: move tape storage and thread_alloc statics to cppad_lib for DLL …#256
Yunsen wants to merge 2 commits into
coin-or:mainfrom
Yunsen:refactor/odr-problem-fix

Conversation

@Yunsen

@Yunsen Yunsen commented Aug 3, 2026

Copy link
Copy Markdown

fixing the odr problem in windows platform, we use middle layer functions defined in cpp files (something like memory allocator) to manage the static/global data. In order to avoid static/global data copy themselves into multiple DLL in windows platform

@CLAassistant

CLAassistant commented Aug 3, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@bradbell

bradbell commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Sorry for the delay in responding. I had to do some updating of CppAD to work with the new version of my development tools. See the recent commits on

 https://github.com/coin-or/CppAD/commits/main/

After merging the current main branch into a local copy of your pull request and running

 tools/check_all.sh --skip_check_copy --skip_external_links

I get the following error:

 ... snip ...
cd build >& check_all.tmp
        cat check_all.tmp >> check_all.log
ninja -j 5 check >& check_all.tmp
Error detected by false result for
    ADBase::tape_ptr() == nullptr
at line 73 in the file 
    /home/bradbell/repo/cppad.git/build/cppad-20260804/include/cppad/core/independent/independent.hpp
... snip ...

When I go into the testing build directory build/cppad-20260804/build and execute ninja check, I get a more detailed error messages that includes

Independent: cannot create a new tape because
a previous tape is still active (for this thread).
AD<Base>::abort_recording() would abort this previous recording.
Error detected by false result for
    ADBase::tape_ptr() == nullptr
at line 73 in the file
    /home/bradbell/repo/cppad.git/build/cppad-20260804/include/cppad/core/independent/independent.hpp
test_more_deprecated_chkpoint_one: /home/bradbell/repo/cppad.git/build/cppad-20260804/include/cppad/utility/error_handler.hpp:204: static void CppAD::ErrorHandler::Default(bool, int, const char*, const char*, const char*): Assertion `false' failed.
[6/158] Linking CXX executable test_more/debug_rel/test_more_debug_rel
FAILED: [code=1] test_more/debug_rel/test_more_debug_rel
: && /usr/bin/c++ -g -Wl,--dependency-file=test_more/debug_rel/CMakeFiles/test_more_debug_rel.dir/link.d test_more/debug_rel/CMakeFiles/test_more_debug_rel.dir/debug_rel.cpp.o test_more/debug_rel/CMakeFiles/test_more_debug_rel.dir/debug.cpp.o test_more/debug_rel/CMakeFiles/test_more_debug_rel.dir/release.cpp.o -o test_more/debug_rel/test_more_debug_rel -L/home/bradbell/repo/cppad.git/build/prefix/lib64   -L/home/bradbell/repo/cppad.git/build/prefix/lib   -L/home/bradbell/repo/cppad.git/build/cppad-20260804/build/cppad_lib  && :
/usr/bin/ld.bfd: test_more/debug_rel/CMakeFiles/test_more_debug_rel.dir/release.cpp.o: in function `CppAD::thread_alloc::thread_num()':
/home/bradbell/repo/cppad.git/build/cppad-20260804/include/cppad/utility/thread_alloc.hpp:585:(.text+0x60): undefined reference to `CppAD::thread_alloc::set_get_thread_num(unsigned long (*)(), bool)'
/usr/bin/ld.bfd: test_more/debug_rel/CMakeFiles/test_more_debug_rel.dir/release.cpp.o: in function `CppAD::thread_alloc::get_memory(unsigned long, unsigned long&)':
/home/bradbell/repo/cppad.git/build/cppad-20260804/include/cppad/utility/thread_alloc.hpp:700:(.text+0x6d): undefined reference to `CppAD::thread_alloc::thread_info(unsigned long, bool)'

You will need to install xrst, so you can build the new documentation during your testing of CppAD. You can do this with the command:

pip install xrst

One thing you should fix. CppAD switched from 3 spaces for tabs to 4 because 4 is more standard (used by more devleopers).

Another thing I would do in the first pull request is to just add the smipler new file

cppad_lib/tape_storage.cpp

Once we get this up and running, the others should be easier.

P.S. I will add the new xrst developer documentation for the new function in tape_storage.cpp, so you can see how that is done.

Thanks.

@Yunsen

Yunsen commented Aug 5, 2026

Copy link
Copy Markdown
Author

OK!Since I am occupied by other things these days and I am not familiar with the xrst tools, the task will be delayed for some days.

@bradbell

bradbell commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

I forgot to mention that there is a way to compile and run just one of the tests or examples, case you are having trouble with ninja check taking to long. If you run

tools/run_cmake.sh

It will create a file called tools/test_one.sh that can be used to run one test or example by its self. There also are many sub targets of check (that check a specific group of tests or examples, that are reported during run_cmake.sh).

@bradbell

bradbell commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

OK!Since I am occupied by other things these days and I am not familiar with the xrst tools, the task will be delayed for some days

You can use the following commands to compile and run most of the C++ tests:

tools/run_cmake.sh
cd build
ninja check
``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants