Opened 5 years ago

Closed 5 years ago

#58379 closed defect (fixed)

LyX @2.3.2: AppleScriptProxy.cpp:39:2: error: use of undeclared identifier 'strcpy'

Reported by: kencu (Ken) Owned by: kurthindenburg (Kurt Hindenburg)
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc:
Port: LyX

Description

When building LyX on systems that are not configured to use libc++ (the default for darwin < 13) the build of Lyx fails:

AppleScriptProxy.cpp:39:2: error: use of undeclared identifier 'strcpy'
        strcpy (cstr, rval.c_str());
        ^

The same build with the same compiler works if building LyX against the libc++ headers.

The file that fails is a bit complicated:

$ cat ./src/support/AppleScriptProxy.cpp
// -*- C++ -*-
/**
 * \file AppleScriptProxy.cpp
 * This file is part of LyX, the document processor.
 * Licence details can be found in the file COPYING.
 *
 * \author Benjamin Piwowarski
 *
 * Full author contact details are available in file CREDITS.
 */
#include <config.h>

#include "AppleScript.h"

#include "DispatchResult.h"
#include "FuncRequest.h"
#include "LyX.h"
#include "LyXAction.h"

#include "frontends/Application.h"

#include "support/docstring.h"
#include "support/debug.h"

#include <stdlib.h>

using namespace std;
using namespace lyx;

extern "C" LyXFunctionResult applescript_execute_command(const char *cmd, const char *arg) {
	LYXERR(Debug::ACTION, "Running command [" << cmd << "] with arguments [" << arg << "]");
	FuncRequest fr(lyxaction.lookupFunc(cmd), from_utf8(arg));
	fr.setOrigin(FuncRequest::LYXSERVER);
	DispatchResult dr;
	theApp()->dispatch(fr, dr);

	string const rval = to_utf8(dr.message());
	char *cstr = (char*) malloc((rval.size()+1)*sizeof(rval[0]));
	strcpy (cstr, rval.c_str());

	// Returns the result
	LyXFunctionResult result;
	result.code = dr.error() ? -1 : 0;
	result.message = cstr;

	return result;
}

But something about that file seems make the build against macports-libstdc++ unhappy.

I tried various modifications to the strcpy command, like:

::strcpy

and 

std::strcpy

but that didn't work. However, adding

#include <stdlib.h>
+#include <string.h>

does fix the build on 10.6 through 10.8. This fix is only needed if not building against libc++.

At this moment, I'm not really certain why this is happening. This is a trial-and-error observation/fix.

I'll generate a PR to fix this.

Attachments (2)

lyx-build-fail-gcc-headers.log (333.8 KB) - added by kencu (Ken) 5 years ago.
build failure
patch-lyx-applescriptproxy-add-stringh-stdlib-macportslibstdcpp.diff (287 bytes) - added by kencu (Ken) 5 years ago.
trivial patch to apply to non-libc++ builds

Download all attachments as: .zip

Change History (6)

Changed 5 years ago by kencu (Ken)

build failure

Changed 5 years ago by kencu (Ken)

trivial patch to apply to non-libc++ builds

comment:1 Changed 5 years ago by jmroot (Joshua Root)

No reason to restrict this patch to certain configurations (or not to send it upstream); using strcpy without including string.h is always wrong.

comment:2 Changed 5 years ago by kencu (Ken)

Thanks. I actually don't really understand how it is building without error on systems using libc++. Must be something about the way that strcpy is being undefined with the gcc c++ headers, I guess.

I'll add in the fact that clang < about 800 can't build this as well, and push the whole thing through. I'll see what i can sell upstream.

comment:3 Changed 5 years ago by jmroot (Joshua Root)

It would likely just be a matter of certain other headers happening to include string.h, masking the problem.

comment:4 Changed 5 years ago by kencu (Ken)

Resolution: fixed
Status: assignedclosed

In 7a47e244dbf488811c0ba96e23c1051cf02ee490/macports-ports (master):

LyX: fix build on older systems

add missing header that seems to manifest only with the gcc headers
(when using stdlib=macports-libstdc++)

blacklist clang version that can't build this this port

closes: #58379

Note: See TracTickets for help on using tickets.